开发者

jQuery ajax forms with json response

开发者 https://www.devze.com 2023-03-18 18:34 出处:网络
Im having troubles trying to figure out why my JSON data.email response is returning null.Can anyone advise?

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

精彩评论

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