zoukankan      html  css  js  c++  java
  • 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();
            }
        }
  • 相关阅读:
    Linux定时运行程序脚本
    git tips
    Python循环
    Head First Design Patterns
    animation过渡效果
    图像处理池化层pooling和卷积核
    TensorFlow的梯度裁剪
    神经网络优化方法总结:SGD,Momentum,AdaGrad,RMSProp,Adam
    CNN网络架构演进
    TensorFlow object detection API应用
  • 原文地址:https://www.cnblogs.com/nelsonlei/p/11313868.html
Copyright © 2011-2022 走看看