防止表单重复提交

1.设置表单提交标志符
isSent=0 表示还没有提交,
isSent=1 表示表单正在提交,禁止重复提交

  1. ajax提交模式禁止异步提交
    增加参数 async: false

    <!DOCTYPE html>  
    <html>  
    <head>  
    <title>防止表单重复提交</title>  
    <script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>  
    </head>  
    <body>  
     <a href="javascript:;">aaa</a>  
     <script>  
     //防止表单重复提交  
         var isSent=0;  
         $('a').click(function(){  
         if(isSent!=0){  
             return;  
         }  
         $.ajax({  
             type: 'GET',  
             url: "http://localhost/test.php",  
             cache:false,  
             async: false, //禁止异步提交  
             success: function (){  
                 console.log('aaa');  
             }  
         });  
         isSent=0;  
         });  
     </script>  
    
    </body>  
    </html>
    
文章目录