从域返回 json 时遇到问题。
在一个文件中,我有以下内容
var postData ="domain=testing.gr";
$.ajax({
type: "POST",
dataType: "json",
data: postData,
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/json;charset=UTF-8");
}
},
url: 'http://www.ewebs.gr/advprodigy/adv.php',
success: function(data) {
// 'data' is a JSON object which we can access directly.
// Evaluate the data.success member and do something appropriate...
if (data.success == true){
$('#keimeno').html(data.message);
}
else{
$('#keimeno').html(data.message);
}
}
});
...在 PHP 文件中,我对以下内容进行了硬编码:
<?php header('content-type: application/json');
$domain = $_POST['domain'];
// Set up associative array
$data = array('success'=> true,'message'=>'Success message: hooray!');
// JSON encode and send back to the server
echo json_encode($data);
?>
但是我在返回时遇到错误..响应是空的! http://prntscr.com/x333k