I have an ajax call where a redirect happens after the call returns (inside the success handler):
$.ajax({
type: "POST",
url: "/LoadSomeData",
dataType: "json",
success: function (response) {
location.href = "http://mysite.com";
}
});
If I do a redirect before the call returns, will the ajax call get cancelled? For example:
$.ajax({
type: "POST",
url: "/LoadSomeData",
dataType: "json",
success: function (response) {
location.href = "http://mysite.com";
}
});
location.href = "http://mysite.com";
I have a situation where I don't really care to wait till all my data is loaded, and I'd like to redirect immediately. Question is will redirecting (possibly before the loading has completed) disrupt the loading process?
Thanks...
ajax appears to always follow redirects.
What triggers Ajax success? Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess event. Any and all handlers that have been registered with the . ajaxSuccess() method are executed at this time.
ajax() function returns the XMLHttpRequest object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the xhr option.
ajax is asynchronous (i.e. non-blocking) by default, that's what the A in Ajax means.
If you redirect outside ajax callbacks, the callbacks will be destroyed and you will redirect immediately. This should have no impact on loading process of the redirected address.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With