jq 停止/结束多个ajax请求

  页面按钮:

  

<button id="song">abort</button>

 

  

  请求:

    

 1 var str = {}
 2     str.xhr = $.ajax({
 3         type: 'get',
 4         url: 'http://xxx.xxx.xxx.x:9202/performance/getPerformanceRankList?phone=13544511617&locale=zh&gridRank=1001&sortColumn=&order=&page=0&pageSize=10&queryStr=&_=1565081256257',
 5         success: function () {}
 6     });
 7     str.xhr1 = $.ajax({
 8         type: 'get',
 9         url: 'http://xxx.xxx.xxx.xx:9202/performance/getPerformanceRankList?phone=13544511617&locale=zh&gridRank=1001&sortColumn=&order=&page=0&pageSize=10&queryStr=&_=1565081256257',
10         success: function () {}
11     });
12     str.xhr2 = $.ajax({
13         type: 'get',
14         url: 'http://x.xx.xxx.x:9202/performance/getPerformanceRankList?phone=13544511617&locale=zh&gridRank=1001&sortColumn=&order=&page=0&pageSize=10&queryStr=&_=1565081256257',
15         success: function () {}
16     });
17     console.log(str.xhr,str.xhr1,str.xhr2);

 

  执行 结束ajax请求,并发送新的请求:

    

 1 $("#song").click(function () {
 2         Abort(str)
 3         setTimeout(function () {
 4             str.xhr3 = $.ajax({
 5                 type: 'get',
 6                 url: 'http://xxx.xx.xx.xx:9202/performance/getPerformanceRankList?phone=13544511617&locale=zh&gridRank=1001&sortColumn=&order=&page=0&pageSize=10&queryStr=&_=1565081256257',
 7                 success: function () {}
 8             });
 9         }, 500)
10     })

 

  结束ajax请求的方法:

function Abort(str) {
        for(var i in str){
            str[i].abort();
        }
    }

 

posted @ 2019-08-07 10:44  小旺同学  阅读(741)  评论(0编辑  收藏  举报