Im having troubles trying to figure out why my JSON data.email response is returning null. Can anyone advise?
我在试图弄明白我的JSON数据的原因时遇到了麻烦。电子邮件回复返回null。谁能建议?
//javascript
$.ajax(
{
type: 'POST',
url: 'process.php',
dataType: 'json',
data: { email : "me@home.com" },
success: function(data)
{
alert("result = "+data.email);
}
});
//php (process.php)
if ($_POST['email'])
$return['email'] = $_POST['email'];
else
$return['email'] = "no email specified";
echo json_encode($return);
1 个解决方案
#1
1
whoops, missed the call to json_encode. Still, you need to set the Content-Type of the response to 'application/json' in the php
哎呀,错过了对json_encode的调用。不过,您仍然需要将响应的内容类型设置为php中的“application/json”
#1
1
whoops, missed the call to json_encode. Still, you need to set the Content-Type of the response to 'application/json' in the php
哎呀,错过了对json_encode的调用。不过,您仍然需要将响应的内容类型设置为php中的“application/json”