weixin_33725807 2015-12-01 19:10 采纳率: 0%
浏览 29

Ajax响应处理

I use this lines to processing responseText from Ajax call.

response=JSON.parse(xmlhttp.responseText)
    len=response.length;
    console.log(len);
    for(i=0;i<len; i++){
        console.log(i);
        alert(response[i].IPO)
        //COCView.lb01Select.appendChild(new DOMtag('option'{'id':response[i].CO_HDR_ID,'innerHTML':response[i].ONR}));
    }
}

After i want to use the inside function(appendChild), I can fetch only the first object of the response array! Could help me somebody, why stops the cycle?

  • 写回答

2条回答 默认 最新

  • weixin_33704591 2015-12-01 19:20
    关注

    I would try putting all of that inside an anonymous function and see if that helps, such as:

    JSON.parse(xmlhttp.responseText, function(response){ 
      len=response.length;
      console.log(len);
      for(i=0;i<len; i++){
        console.log(i);
        alert(response[i].IPO)
        //COCView.lb01Select.appendChild(new DOMtag('option'{'id':response[i].CO_HDR_ID,'innerHTML':response[i].ONR}));
      }
    });
    

    Also, dump what you are getting for "response" and see if that is what you expect.

    评论

报告相同问题?