I have this jQuery code that send an Ajax request on a form submit. My issue is I can't catch timeout error using that code. When I send a 500 response myself it is working but if I get a timeout then I see 500 in the console but nothing happens, the error callback is not executed. Instead I get :
SyntaxError: syntax error
On the line:
$(document).ready(function(){
Here is the full code:
$(document).ready(function(){
$('body').on('submit', 'form#myForm', function(){
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: $(this).serialize(),
dataType: 'json',
success: function(data, textStatus, jqXHR){
alert('success!');
},
error: function(jqXHR, textStatus, errorThrown){
alert('error!');
}
});
return false;
});
});