开发者

jQuery Ajax Form submit - Disable on submit

开发者 https://www.devze.com 2023-01-28 11:12 出处:网络
Ajax form submit usability. when i submit the form i wanna di开发者_如何学JAVAable the form to be submited till the previous submission happens. can i do this by just disabling the input or text area

Ajax form submit usability. when i submit the form i wanna di开发者_如何学JAVAable the form to be submited till the previous submission happens. can i do this by just disabling the input or text area or should i disable the submit button too ?


You can disable form-submission by letting its onsubmit-handler return false:

<form onsubmit="return false">...

Of course you would have a javascript-function which decides whether to submit or not:

<form onsubmit="return myDecisionFunction()">...

The decision-function in your case could look like this:

var submissionEnabled = true;
function myDecisionFunction() {
   if (submissionEnabled) {
       submissionEnabled = false;
       return true;
   } else {
       return false;
   }
}

And after the ajax-response came in, you enable it again:

submissionEnabled = true;


I did this by disabling the submit button.

$("#submit").click(function(){
    $(this).attr('disabled', 'disabled');
    $("#form").submit();
})
0

精彩评论

暂无评论...
验证码 换一张
取 消