$.ajax({
type: 'POST',
url: 'place/add',
data: {
lat: lat,
lng: lng,
name: name,
address: address,
phone: phone,
review: review,
category: category
},
success: function(data) {
alert(data);
alert(data.id);
// ......
});
第一个警报给出:{"id":"2","success":true}
,但第二个警报给出:undefined
最佳答案
您需要将预期返回的数据类型指定为 JSON:
$.ajax({
type: 'POST',
dataType: 'json', // specifies the return type
url: 'place/add',
data: {
lat: lat,
lng: lng,
name: name,
address: address,
phone: phone,
review: review,
category: category
},
success: function(data) {
alert(data);
alert(data.id);
// ......
}
});
关于javascript - 调试 jQuery AJAX 响应 : what I'm doing wrong?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1696271/