Imagine the first time, the data doesn’t matched and ajax has returned the request then sending an error message to the form, after that how do i stop ajax call if there’s no changes made on the form/input?
$("input[name=signup]").click(function(event) {
if ($(this).attr('type') == "submit" && $(this).attr('name') == "signup") {
formValidate = function() {
$.ajax({
url: "/ajax/req-signup.aspx",
type: "post",
dataType: "json",
data: { ... },
success: function(response) { ... }
});
}
formValidate();
}
event.preventDefault();
});
add a global variable
set it to false when validation fails:
set to true when changing something in the form
and check it’s status when making the ajax call:
Alternatively, you can disable the submit button when the validation fails and enable it on change.
If you don’t mind using a plugin, check out jQuery disabler widget, you might find it easier to use.