Disabling default action (return false) even when action is set to .off
I have a registration submit button on my website that is handled with
Jquery. The problem is that I want to prevent people from clicking on it
more than once while it is going through the process of registering their
account. For this reason I disable the click event once they have clicked
it, and do not re-enable the click unless there is an error. See bwlow
function registerClick() {
$('#register_submit').off('click',registerClick);
$.ajax( {
type: "POST",
url: "/ajax/register.ajax.php",
data: $("#register_form").serialize(),
success: function(data) {
var result = jQuery.parseJSON(data);
if (result.success) {
alert('Account registered. You are now being transferred
to Paypal for payment.');
window.location = result.success;
} else if (result.error) {
alert(result.error);
$('#register_submit').on('click',registerClick);
} else {
alert('Unhandled exception');
$('#register_submit').on('click',registerClick);
}
}
});
return false;
};
// signup
$('#register_submit').on('click',registerClick);
What unfortunately happens now is that if they double click the button,
the second click triggers the default button action which is to submit the
form to #.
I'm thinking that maybe I need to disable the button all together, but I'm
new to Jquery so this is uncharted territory for me.
No comments:
Post a Comment