1
我想下面的代码来获取for循环中的一些URL,并添加所有数据在文本变量和for循环完成后,我试图检查文本,但它说undefined看起来像ajax调用尚未完成。jquery Ajax等待异步响应
var text;
for (i = 0; i < 4; i++)
{
link=links[i];
$.ajax({
url: scriptLnks,
crossDomain: true,
dataType: 'text',
success: function (result)
{
text+= result;
}
});
}
alert(text);
我希望它只是异步的。请帮忙。
可能重复[如何从异步调用返回响应?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-调用) – Andreas
[如何等待,直到jQuery ajax请求在循环中完成?](https://stackoverflow.com/questions/20291366/how-to-wait-until-jquery-ajax-request-finishes-in -一个循环) –