Abort doesn't seem to close the connection
Hi,
I have been fighting with JQuery, and I got beaten badly.
What I try to do is launching an ajax request, and if I don't get the answer soon enough, launching another one.
The problem is that I have to wait for the 1st one to complete in order to get the result of the second one (even with the abort method)
This is my code (test 1 is called first and it calls a php function which waits 10s, then return something (so we have the timeout instead of the return of the function) and calls test2 in case of an error. test2 calls to another php function that immediately return something.
What I expect to have is: test1 got a timeout, launches test2, and i get the test2 results
What I have is: test1 got a timeout, launches test2 which got a timeout as well.
What I have seen from my tests (if I don't put any timeout in the test2 function) is that I have to wait that my php function 1 finished before having the result, and I try to cancel that behaviour.
This is my code:
- var ajax_request;
- function test1()
- {
- ajax_request=$.ajax({
- url: "url to test1 php",
- data: "test",
- timeout: 1000,
- success:function(data)
- {
- alert(data);
- },
- error: function (xhr, textStatus, errorThrown) {
- $ajax_request.abort();
- test2();
- alert("aborted");
- }
- });
- }
- function test2()
- {
- ajax_request=$.ajax({
- url: "url to test 2 php",
- data: "test",
- timeout: 1000,
- success:function(data)
- {
- alert(data);
- },
- error: function (xhr, textStatus, errorThrown) {
- alert(textStatus);
- }
- });
- }
Thank you in advance!