2011-07-06 83 views
2

我有麻烦试图找出为什么我的JSON data.email响应返回null。任何人都可以建议吗?jQuery的Ajax形式与JSON响应


//javascript 
$.ajax(
{ 
type: 'POST', 
url: 'process.php', 
dataType: 'json', 
data: { email : "[email protected]" }, 
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

哎呀,错过了对json_encode的调用。 但是,您需要在php

中将响应的内容类型设置为'application/json'