首页 > JS for循环内jQuery.post回调函数调用问题

JS for循环内jQuery.post回调函数调用问题

代码片段

b = ['AY120723082752d383204','AY1211161250020447524'];

for (l in b) {
    instanceId = b[l];
    jQuery.post('plugin.php?id=host:host&page=firewall&action=applyecs&instanceId=' + instanceId, function(a) {
        if (a.replace(/[\r\n]/g, '') == '0') {
                     console.log( instanceId );
        }
    })
}

最终console.log出始终是

AY1211161250020447524
AY1211161250020447524

但CHROME截取数据包可以发现请求出去的instanceId参数是按预期执行的, 何种方法能让不修改服务器后端返回数据类型时 回调函数调用到请求出去时的instanceId参数的值?

JS新手,好人一生平安

按照 @怡红公子 的“用$.ajax(),设置async: false”建议,解决了

【热门文章】
【热门文章】