zoukankan      html  css  js  c++  java
  • jQuery实现ajax的叠加和停止(转)

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>jQuery中终止Ajax请求</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://common.cnblogs.com/script/jquery.js" type="text/javascript"></script>
        <script>
            var arrayAJAX = new Array();
            $(function () {
                $("#btn").bind("click", function () {
                    for (var i = 0; i < 100; i++) {
                        starAJAX(i);
                    }
                });
    
                $("#bt2").bind("click", function () {
                    stopAJAX();
                    alert("终止AJAX请求");
                });
    
            })
    
            //停止ajax
            function stopAJAX() {
                for (var i = 0; i < arrayAJAX.length; i++) {
                    arrayAJAX[i].abort();
                }
                arrayAJAX = new Array();
            }
    
            //添加ajax
            function starAJAX(i) {
                var options = {
                    url: '/Home/addallrecommandbook',
                    data: "html=" + i,
                    success: function (data, textStatus) {
                        if (textStatus == 'success') {
                            alert("添加成功!");
                        }
                        else {
                        }
                    },
                    error: function (x, msg, err) {
                    }
                };
                arrayAJAX.push($.ajax(options));
            }
        </script>
    </head>
    <body>
        <input type="button" id="btn" value="starAJAX" />
        <input type="button" id="bt2" value="stopAjax" />
    </body>
    </html>

    注:转载自http://www.cnblogs.com/rhythmK/archive/2012/10/09/2716249.html

  • 相关阅读:
    nyoj 17 单调递增最长子序列
    nyoj 18 The Triangle
    nyoj 712 探 寻 宝 藏
    nyoj 61传纸条(一)
    nyoj 269 VF
    nyoj 44 子串和
    nyoj 252 01串
    nyoj 42 一笔画问题
    nyoj 756 重建二叉树
    Table 样式设置
  • 原文地址:https://www.cnblogs.com/liushenghuan/p/5749674.html
Copyright © 2011-2022 走看看