We have our authentication delegated to another domain (Window Identify framework, federated authentication setup). Now, if the the session timed out before an ajax request , server redirects the request to authentication server. Since it becomes a cross domain call, ajax request is cancelled by the browser. Is there a way i can detect this in jquery/javascript ?
I inspected the status property of the xhr object which set to 0 in such case, but is it a good indicator for cancelled requests? (I am using jquery $.ajax to make ajax requests)
I have been looking into this, too, and have found very little evidence that what you want to detect is perfectly detectable. However, I have found a way to detect that it probably happened.
Here is what transpires with your event:
In your error callback, check your XMLHttpRequest
object's readyState
field. If it is 0 ("UNSENT"), then it means that your AJAX request was never sent.
Of course, it may not always be entirely clear why it was not sent. For example, it's possible that the user simply unplugged his network cable. However, if you are willing to assume that the network is functioning perfectly, then it may be reasonable to also assume, when you see readyState == 0
, that the request was not sent because of cross-domain concerns. That means the redirect happened.
If you are working with jQuery, then you can check jqXHR.readyState
instead.
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