Multiple ajax calls from array and handle callback when completed

前端 未结 2 466
别那么骄傲
别那么骄傲 2020-12-05 02:58

I have used promises in jQuery slightly before - but I am having trouble applying it to this scenario. I prefer to use the $.when() and $.done() methods to achieve this.

2条回答
  •  天涯浪人
    2020-12-05 03:38

    I share an easy example that could help you to handle multiple requests and their responses:

    var arr = [
        $.ajax({url:"test1.php"}),
        $.ajax({url:"test2.php"}),
        $.ajax({url:"test3.php"})
    ];
    $.when.apply( undefined, arr ).then(function() {
        var objects=arguments;
        console.dir(objects);
    });
    

提交回复
热议问题