我对 ajax 比较陌生,并且已经查看了大量其他线程,但找不到答案。
我正在尝试读取 .post 调用的结果,但没有成功。
这是代码:
$.post( http://www.mapquest.com/directions/v1/routematrix?key=...,//I have my actual key where the three dots are
{locations:[{latLng:{lat:54.0484068,lng:-2.7990345}},{latLng:{lat:53.9593817,lng:-1.0814175}},{latLng:{lat:53.9593817,lng:-1.0514175}},{latLng:{lat:53.9593817,lng:-1.0114175}}]},
function (data, status, xhr) {
console.log(typeof(data)); //this shows: object
console.log(data); //this shows: [object object]
console.log(data[0]); //this shows: undefined
console.log(data.length); //this shows: undefined
console.log(status); //this shows: success
},
'json'
);
我期待的输出看起来像这样:
{
allToAll: false,
distance: [
0,
25.685,
107.846,
78.452
],
time: [
0,
2260,
7253,
5930
],
locations: [
"Lancaster, England",
"Liverpool, England",
"Chester, England",
"Stoke-on-Trent, England"
],
info: {
...
}
}
知道我做错了什么吗?