通过表单将json发送到php

时间:2021-07-04 18:15:48
$('<form method="post" action="login/makeLogin"><input type="hidden" name="fbphoto" value="'+image +
                    '"><input type="hidden" name="fbname" value="'+response.first_name +'"><input type="hidden" name="fbemail" value="'+response.email +'"><input type="hidden" name="fbid" value="'+response.id+
                    '"><input type="hidden" name="fbsurname" value="'+response.last_name +'"><input type="hidden" name="fbfriends" value="'+json +'"></form>').appendTo('body')

I create this form dynamicly with javascript. But when I try to send this form to a php function, it returns false when I try to access the fbfriends property the rest values work fine. The value of fbfriends is a string containing json, which I get using:

我用javascript创建了这个表单。但是当我尝试将这个表单发送到php函数时,当我试图访问fbfriends属性时,它会返回false, rest值可以正常工作。fbfriends的值是一个包含json的字符串,我使用它:

var json=JSON.stringify(response.friends);

If I dont stringify the json I get a string [Object object] when retrieving values in the php function. How can I send json through a form.

如果不对json进行字符串化,在php函数中检索值时就会得到一个字符串[Object]。如何通过表单发送json ?

1 个解决方案

#1


1  

Your form only contains hidden items. Why don't you post the response values through $.ajax directly?

您的表单只包含隐藏项。为什么不通过$发布响应值呢?ajax直接吗?

#1


1  

Your form only contains hidden items. Why don't you post the response values through $.ajax directly?

您的表单只包含隐藏项。为什么不通过$发布响应值呢?ajax直接吗?