I would like to intercept response from REST request as $httpProvider.interceptors does in agularjs : https://docs.angularjs.org/api/ng/service/$http
I am making a very little interface with jQuery and would not like to use angular just for this. Do you have and Idea ?
Actually my real problem to fix is the same as this one : Dealing with a 301 and location headers for a REST response in cross-domain
But I would like to solve it the same way with jquery.
I tried this without success : (only catch a 0 status never a 301...)
How can I intercept ajax responses in jQuery before the event handler?
To answer V31, I did this :
$.ajaxSetup({
error: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 301) {
alert("Element not found.");
} else {
console.log(jqXHR.status);
console.log("Error: " + textStatus + ": " + errorThrown);
}
}
});
Here is my console :
Which says :
XMLHttpRequest cannot load *******. The request was redirected to '**************', which is disallowed for cross-origin requests that require preflight.
0
Error: error: