zoukankan      html  css  js  c++  java
  • jq阻止ajax进行多次提交

    在函数定义全局变量..var Stch=false
    if (Stch==true)
    {
    alert('请不要重新提交');
    }else{
    Stch=true;
    $.ajax({type:"POST",
    url:"C_Eidt.do",
    golobal:false,
    success:function(data){
    Stch=false;
    };});
    }

    或者 使html页面上按钮变灰

    2..多次绑定click及ajax提交的常用方法

    <script>
    $(document).ready(function()
    {
        //绑定click
        $(".exchange_ecv").bind("click", function()
        {
            var p=$(this).attr("name");
              var types=$(this).attr("type");
            var tid=$(this).next().attr("id");
            if(types=="0"){
                var m=100000;
            }else if(types=="1"){
                var m=500000;
            }else if(types=="2"){
                var m=1000000;
            }
            document.getElementById('lightqd').style.display='block';
            document.getElementById('fade').style.display='block';
            //第二次绑定click 会出现多次click现象
            $("#qd").bind("click",function()
            {
                exchange_ecv(p,tid,m,types);
                document.getElementById('lightqd').style.display='none';
                document.getElementById('fade').style.display='none';
                $("#qd").unbind("click"); //去除多次click
            });
        });
    
        //ajax提交
        function exchange_ecv(p,tid,m,types){
            var query = new Object();
            if({$user_id}>0){
                query.id={$user_id};
                query.prize=p;
                query.types=types;
            }else{
                document.getElementById('light').style.display='none';
                document.getElementById('fade').style.display='none'
                ajax_login();
                return false;
            }
    
            $.ajax({
                async:false,
                url:'{url x="index" r="new_year_prize#exchange_ecv"}',
                type:"POST",
                data:query,
                dataType:"json",
                contentType: "application/x-www-form-urlencoded; charset=utf-8", 
                success:function(result){
                    if(result.status==2){//还没登录
                        ajax_login();
                        return false;
                    }else if(result.status==1){ //兑换成功
                        $("#msg").html(result.msg);
                    }else if(result.status==3){  //已经兑换过
                        $("#msg").html(result.msg);
                    }else{ //其它状态
                        $("#msg").html(result.msg);
                    }
                }
            });
    
    
        }
    
    
        //拆红包
        $("#open_ecv").click(function()
        {
            open_ecv();
        });
        function open_ecv()
        {
            var query =new Object();
            if({$user_id}>0){
                query.id={$user_id};
            }else{
                ajax_login();
                return false;
            }
            $.ajax({
                async:false,
                url:'{url x="index" r="new_year_prize#open_ecv"}',
                type:"POST",
                data:query,
                dataType:"json",
                contentType: "application/x-www-form-urlencoded; charset=utf-8", 
                success:function(result)
                {
                    if(result.status==2)
                    {
                        ajax_login();
                        return false;
                    }else if(result.status==1)
                    {
                        // $.showSuccess(result.msg);
                        document.getElementById('light').style.display='block';
                        document.getElementById('fade').style.display='block'
                        $("#msg").html(result.msg);
                    }else
                    {
                        // $.showErr(result.msg)
                        document.getElementById('light').style.display='block';
                        document.getElementById('fade').style.display='block'
                        $("#msg").html(result.msg);
                    }
                }
    
            });
        }
    
    })
        
    </script>

    没人说点击事件只能执行一次。两种办法,一是把on改成one,使得点击提交事件只发生一次;二是点击之后把按钮button禁用(disabled属性),或者移除button上绑定的事件(off方法)。
  • 相关阅读:
    循环链表结构
    复杂的权衡之时间、空间和单链表结构
    单链表操作之删除
    单链表操作之插入
    单链表操作之替换
    单链表操作之搜索
    文件系统的原理
    类加载的三种方式比较
    shell中awk printf的用法
    推荐网站
  • 原文地址:https://www.cnblogs.com/lanyueff/p/7992722.html
Copyright © 2011-2022 走看看