我對ajax比較陌生,並且查看了大量其他線程,但找不到答案。jquery post的undefined結果
我想從.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: {
...
}
}
任何想法,我做錯了嗎?
'數據'似乎是一個對象,它具有'allToAll','distance','time','locations'和'info'屬性,但是不是**'0'或'length'。 –
[Access/process(嵌套)對象,數組或JSON]的可能的重複(http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) –
什麼是錯誤/你看到的輸出? – Stunner