2017-04-03 68 views
1

我寫的JS(阿賈克斯)代碼:的Json數組JavaScript和Ajax

​​

阿賈克斯回到我記錄JSON在陣,看起來就像這樣:

sport_id: 
[{"id":110,"sport_id":1,"league_id":32}] 
league_id: 
[{"id":110,"sport_id":1,"league_id":32}] 

我不能讓只有sport_idleague_id。我想從這個主題enter link description here添加代碼:

if(sport_id[i]._type[0]=='sport_id'){ 
    currentObj = pushNew(sport_id[i].nodeValue); 
} 

但我回來了錯誤:

statusText: OK Status: 200 readyState: 3

回答

0

使用此代碼對你的期望輸出

question.responseType = 'jsonp'; 

    for (x in sport_id) { 
     document.getElementById("sport_id").innerHTML += sport_id[x] + " "; 
    } 

for (x in league_id) { 
     document.getElementById("league_id").innerHTML += league_id[x] + " "; 
    } 
+0

史迪威我有這同樣的錯誤:狀態文本:OK狀態:200 readyState:3 – michal

+0

我已更新代碼。我認爲你的數據格式不是標準的,意味着JSONP –