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
精彩评论