jquery AJAX prevents duplicate submissions
The code is as follows |
|
$.ajax ({ Type: "POST", Url:url, Async:false, DataType: "Script", Success:function (Sigup) { } }); Async:false, |
/*
Get and post methods to prevent repeated requests from Ajax
*/
The code is as follows |
|
Jquery.extend ({ Getx:function (Url,data,callback,sender) { var params={url:url,data:null,callback:null,sender:null}; for (Var i=1;i<arguments.length;i++) { if (arguments[i]!=null) { var ptype=typeof (Arguments[i]); if (ptype== "function") { Params.callback=arguments[i]; } else if (ptype== "string") { params.sender=$ (Arguments[i]); if (Params.sender.data ("isrequesting")) return null; } else if (ptype== "Object") { if (Arguments[i].tagname | | arguments[i].selector) { params.sender=$ (Arguments[i]); if (Params.sender.data ("isrequesting")) return null; } else{ Params.data=arguments[i]; } } } } Params.sender.data ("Isrequesting", true); Return $.get (Params.url,params.data,function (data,status) { Params.sender.data ("Isrequesting", false); if (data== "Unlogin") { Window.top.location.href= "/login.aspx"; Return } if (params.callback) { Params.callback (Data,status); } }); }, Postx:function () { var params={url:url,data:null,callback:null,sender:null}; for (Var i=1;i<arguments.length;i++) { if (arguments[i]!=null) { var ptype=typeof (Arguments[i]); if (ptype== "function") { Params.callback=arguments[i]; } else if (ptype== "string") { params.sender=$ (Arguments[i]); if (Params.sender.data ("isrequesting")) return null; } else if (ptype== "Object") { if (Arguments[i].tagname | | arguments[i].selector) { params.sender=$ (Arguments[i]); if (Params.sender.data ("isrequesting")) return null; } else{ Params.data=arguments[i]; } } } } Params.sender.data ("Isrequesting", true); Return $.post (Params.url,params.data,function (data,status) { Params.sender.data ("Isrequesting", false); if (data== "Unlogin") { Window.top.location.href= "/login.aspx"; Return } if (params.callback) { Params.callback (Data,status); } }); } }) |
JS to prevent form repeat submission
The code is as follows |
|
<script type= "Text/javascript" > var flag = false; function Checksubmit () { if (!flag) { Document.forms[0].submit (); Flag = true; }else { Alert ("duplicate submission"); } } </script> |
For more details please see: http://www.111cn.net/wy/js-ajax/35327.htm