I have a question regarding an issue I ran into, which is connected to these two tickets, which got rejected:
How is it possible to distinguish a failed Ajax request, which failed because the user navigated to another page, from Ajax requests that failed because of errors, not directly triggered by a user action.
Currently I see no way to do so.
1. Navigate browser (tried Chrome 46, Firefox 42) to http://jquery.com
2. Execute the following commands in the JavaScript Console
3. Define fail() callback function
- var onAjaxFailed = function( jqXHR, textStatus, errorThrown){console.log("AJAX failed!", jqXHR, textStatus, errorThrown)}
4. AJAX Request fails because of DNS error
Result:
AJAX failed! Object {readyState: 0, responseText: "", status: 0, statusText: "error"} error
5. AJAX Request fails because of Same-origin policy
Result:
AJAX failed! Object {readyState: 0, responseText: "", status: 0, statusText: "error"} error
6. AJAX Request fails because user navigates to another page
Result:
AJAX failed! Object {readyState: 0, responseText: "", status: 0, statusText: "error"} error
So the arguments to the fail()-callback are always the same on these errors, even though they are very different in nature from my perspective.