这是我第一次使用 JSON。我正在尝试使用 ajax 从 php 脚本中获取 JSON 数据。但我收到此错误“Error.Parsing JSON Request failed”“undefined”。帮帮我这是我的 php 脚本test.php
$data='{
"one": "One",
"two": "Two",
"three": "Three"
}';
header('Content-type: application/json');
echo json_encode($data);
在这里我得到数据getdata.php
var sURL = 'http://www.example.com/test.php';
$.ajax({
type: "GET",
url:sURL,
dataType:"jsonp",
crossDomain:true,
data: {transid:trans_id , bookingdate: dateVal, bookingtime: timeVal, People: peopleVal,affiliateid: affiliate },
async: false,
contentType:"application/json; charset=utf-8",
success: function (data){
var result = JSON.parse(data);
alert(result);
},
error: function (x, e) {
if (x.status == 0) {
alert(x.response);
alert(x + " " + e);
alert('You are offline!!\n Please Check Your Network.');
}
else if (x.status == 404) {
alert('Requested URL not found.');
}
else if (x.status == 500) {
alert('Internel Server Error.');
}
else if (e == 'parsererror') {
alert('Error.\nParsing JSON Request failed.' + e.statusText);
alert(x.response);
} else if (e == 'timeout') {
alert('Request Time out.');
} else {
alert('Unknow Error.\n' + x.responseText);
}
}
});
这是我的第一个问题,请原谅任何错误