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