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();
            }
        }
  • 相关阅读:
    tkinter 改变按钮状态
    python 遗传算法精简版
    极简反传(BP)神经网络
    python 操作注册表
    python 调用 shell 命令方法
    Python标准库:内置函数dict(mapping, **kwarg)
    3.2.2 正則表達式的功能
    NSArray利用Cocoa框架进行汉字排序
    Java多线程具体解释
    android6.0权限管理工具EasyPermissionUtil
  • 原文地址:https://www.cnblogs.com/nelsonlei/p/11313868.html
Copyright © 2011-2022 走看看