我在PHP中创建了一个JSON
http_response_code(400);
header('Content-Type: application/json');
$myObj = array('msg' => "Not a valid email address");
echo json_encode($myObj);
exit();
现在我想将它解码为来自ajax PUT的响应
var booking_Data = JSON.stringify(bookingData);
$.ajax({
type: "PUT",
url: serverip+"/create/job",
data: booking_Data,
contentType: "application/json; charset=utf-8",
dataType: "json",
...
statusCode: {
...
400: function (data) {
console.log(data);
alert(data['msg']);
alert('400');
},
但警报返回undefined。 console.log
的{{1}}显示
data
数据显示正常并获得JSON响应,但似乎无法取消responseJSON : {msg: "Not a valid email address"}
responseText :"{"msg":"Not a valid email address"}"
。