且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在所有AJAX请求完成后采取的措施

更新时间:2021-12-30 06:26:26

您可能正在尝试等待所有ajax调用完成,因为您正在执行多个操作:

You're probably trying to wait until all the ajax calls have completed, as you're doing multiple :

var xhrs = [],
    link = '';

$.each(LinkUnique,function(i){
    var xhr = $.ajax({
                  type: 'POST',
                  url : 'http://xxxx.net/'
              }).done(function(msg) {
                  if(msg.indexOf("http://") !=-1)
                      link = link+msg+"\n";
              });

    xhrs.push(xhr);
});

$.when.apply($, xhrs).then(function() {
    alert(link);
});