Reputation: 11
I have successfully created a loop to infinity. Could someone tell me how to rewrite this so that if the ajax request fails the form is submitted so server side validation can deal with it.
$('form#loginForm').submit(function(evt) {
evt.preventDefault();
// We rely on HTML5 validation for the validation - this checks if the account is valid.
$.ajax({
type: "POST",
url: "some.php",
error: function(msg) {
alert(1);
$('#loginForm').submit();
}
});
});
Upvotes: 1
Views: 603
Reputation: 2118
From your code, when you're calling submit in the error function you're calling the same function that does the ajax call. If you just want to submit the form without doing that ajax call, you need to rebind the submit function;
$('form#loginForm').submit(function(evt) {
evt.preventDefault();
// We rely on HTML5 validation for the validation - this checks if the account is valid.
$.ajax({
type: "POST",
url: "some.php",
error: function(msg) {
alert(1);
//rebind submit function to not do ajax call
$('#loginForm').submit(new function(){return true;});
//then call submit
$('#loginForm').submit();
}
});
});
Upvotes: 6