I have a function hooked on a $('form').submit() event.
This function will fire an ajax request and update the document.
I want to make it it so if an ajax error occurs the form continues to be submitted normally. Is this possible?
I tried return fail_status; on the end of the function (fail_status is a boolean variable that gets updated to “true” in the ajax “error” function), but it doesn’t seem to work…
The code looks something like this:
$('form').submit(function(){
var fail_status = false;
$.ajax(
...
error: function(){
fail_status = true;
}
...
);
return fail_status;
// so if it's true the form should be submitted normally...
});
The issue is that JQuery defaults to Asynchronous. This means that it is returning “fail_status” before it gets the server response.
Your best bet would be to have
error:be a function that submits the form programatically.EDIT: Try rewriting your function: