2017-04-03 66 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 –