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();
})
精彩评论