开发者

jQuery ajax forms with json response

Im having troubles trying to figure out why my JSON data.email response is returning null. Can anyone advise?


//javascript
$.ajax(
{
 type: 'POST',
 url: 'process.php',
 dataType: 'json',
 data: { email : "me@home.com" },
 success: function(data)
 {
  alert开发者_StackOverflow社区("result = "+data.email);
 }
});

//php (process.php)
if ($_POST['email']) 
 $return['email'] = $_POST['email'];
else
 $return['email'] = "no email specified";

echo json_encode($return);


whoops, missed the call to json_encode. Still, you need to set the Content-Type of the response to 'application/json' in the php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜