Disable submit button on form submit [SOLVED]
Hi,
I have a page with many forms that I need to change from a post to an ajax call. That part is working, no problem, but now I want to disable the submit button while it's waiting on the server response and then re-enable it when the response comes back.
Here's what I have:
-
$(function() {
$('form').each(function() {
$(this).submit(function(){
var $that = $(this);
var $submitButton = $(this, "input[type='submit']");
$submitButton.attr("disabled", "true");
jQuery.ajax({
data: $that.serialize(),
url: $that.attr("action"),
timeout: 2000,
error: function() {
alert("Failed to submit");
//submit normal way
return true;
},
success: function(r) {
alert("Update Successful");
$submitButton.attr("disabled", "false");
},
})
return false;
})
});
})
I can't figure out what my selector should be to get the submit button of the form that's being submitted. What should I be using instead? Also, if the call errors out, I'd like to just post the form as usual. Is that possible?
Thank you for the help!