Javascript Ajax响应处理

Javascript Ajax响应处理,javascript,ajax,Javascript,Ajax,我使用这行代码来处理来自Ajax调用的responseText 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 D

我使用这行代码来处理来自Ajax调用的responseText

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}));
    }
}
response=JSON.parse(xmlhttp.responseText)
len=响应长度;
控制台日志(len);

对于(i=0;i我会尝试将所有这些放在匿名函数中,看看这是否有帮助,例如:

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}));
  }
});
JSON.parse(xmlhttp.responseText,函数(response){
len=响应长度;
控制台日志(len);

对于(i=0;i我会尝试将所有这些放在匿名函数中,看看这是否有帮助,例如:

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}));
  }
});
JSON.parse(xmlhttp.responseText,函数(response){
len=响应长度;
控制台日志(len);

因为(i=0;i问题与AJAX无关,问题是循环过程。 如果在循环中有函数,则在数组上使用for(){}循环进程将停止。正确的数组循环解决方案是:

anyfunc=function(x,y,z){..}
array1=[{"id":'one',"IPO":'anyIPOValue'},{"id":'two',"IPO":'anyIPOValue'}];
for(n of array1){
    if (n.id || n.IPO){anyfunc(n.id,n.id,n.IPO);}
    }

问题与AJAX无关,问题是循环过程。 如果在循环中有函数,则在数组上使用for(){}循环进程将停止。正确的数组循环解决方案是:

anyfunc=function(x,y,z){..}
array1=[{"id":'one',"IPO":'anyIPOValue'},{"id":'two',"IPO":'anyIPOValue'}];
for(n of array1){
    if (n.id || n.IPO){anyfunc(n.id,n.id,n.IPO);}
    }

你在
函数(appendChild)
中的意思是什么?你的代码的其余部分在哪里?'response'是什么样子的?我的意思是:在激活COCView..line之后,循环停止..实际上我只想用sresponse填充一个对象,比如:[{“CO_HDR_ID”:“1”},{“CO_HDR_ID”:“2”}]它是jsonized你说的函数(appendChild)的内部是什么意思?你的代码的其余部分在哪里?响应是什么样子的?我的意思是:在激活COCView..行之后,循环停止..实际上我只想用响应填充一个对象,比如:[{“CO_HDR_ID”:“1”},{“CO_HDR_ID”:“2”},它是jsonized的