Reputation: 784
I need to make some ajax calls to a php script that will process the data and display the results.
But the calls seem to be timing out. in Chrome and Firefox when i check the calls they show up in red.
my ajax code:
$.ajax({
type: "POST",
url: "/toimport",
data: ({"filename": $("#file").val(), "search_engine": $("#engine").val(), "matchtype": $("#matchtype").val(), "year" : $("#year").val(), "country" : country, "sheet" : i, "filetype": file_type}),
success: function(data, textStatus, jqXHR){
$("#message").append(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
$("#message").append(textStatus + '<br />');
}
});
when I make the PHP code trivial (return one of the received values), all the calls are successful, it is only when the PHP takes some time that the ajax call fails.
I tried using timeout on the ajax call, but it doesn't seem to work. The textStatus returned is 'error', errorThrown is empty.
thanks
Upvotes: 1
Views: 581
Reputation: 71
You can handle your AJAX call this way:
var ajaxCall = $.ajax(options);
You can abort your call if you have the reference to your AJAX call:
ajaxCall.abort();
You need to make extra validations to know if your AJAX call has been done or still working to avoid any error on your abort
request.
Upvotes: 1