How can I call my function: myFunc1
in jquery
after the browser has completely sent an ajax request?
I want to run a callback function after a jquery ajax has been sent. I don't want to do this on complete
or success
because I don't want to wait for the request to complete. I want to fire it right after the ajax request has been sent from the browser.
This is use case for which i need this:
I want run a function after making an ajax request. My original code was this:
$.ajax({url: 'x.html'});
myFunc1();
In the case when `myFunc1() changes the browsers location, the browser would cancel the pending ajax request.
My current solution is to do this:
$.ajax({url: 'x.html', complete: myFunc1});
This makes sure that myFunc1
is not called till the ajax is complete. Although this solution works, it is inefficient because myFunc1
wont run till the request is complete. Since I don't care what the ajax request returns, whether it fails or succeeds, I dont need to wait for it to complete to run the myFunc1
function.