title: How to catch an expected (and intended) 302 Ajax response?
body: <p>So, if you look back at my <a href="https://stackoverflow.com/questions/2764444/getting-autodiscover-url-from-exchange-email-address">previous question</a> about Exchange Autodiscover, you'll see that the easiet way to get the autodiscover URL is to send a non-secure, non-authenticated <code>GET</code> request to the server, ala:</p>
  <p><a href="http://autodiscover.exchangeserver.org/autodiscover/autodiscover.xml" rel="nofollow noreferrer">http://autodiscover.exchangeserver.org/autodiscover/autodiscover.xml</a></p>
  <p>The server will respond with a 302 redirect with the correct url in the <code>Location</code> header.</p>
  <p>I'm trying out something really simple at first with a Chrome extension, where I have:</p>
  <pre><code>if (req.readyState==4 &amp;&amp; req.status==302) {
      return req.getResponseHeader(&quot;Location&quot;);
  }
  </code></pre>
  <p>With another ajax call set up with the full XML Post and the user credentials,</p>
  <p>But instead Chrome hangs at this point, and a look at the developer panel shows that it is not returning back the response but instead is acting like no response was given, meanwhile showing a</p>
  <pre><code>Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101
  </code></pre>
  <p>in the error log.</p>
  <p>The way I see it, refering to the exact response status is about the same as &quot;catching&quot; it, but I'm not sure if the problem is with Chrome/WebKit or if this is how XHR requests always handle redirects.</p>
  <p>I'm not sure how to catch this so that I can get still get the headers from the response.</p>
  <p>Or would it be possible to set up a secondary XHR such that when it gets the 302, it sends a totally different request?</p>
  <h3>Quick Update</h3>
  <p>I just changed it so that it doesn't check the response code:</p>
  <pre><code>if (req.readyState==4) {
      return req.getResponseHeader(&quot;Location&quot;);
  }
  </code></pre>
  <p>and instead when I alert out the value it's <code>null</code>. and there is still the same error and no response in the dev console. SO it seems like it either doesn't track 302 responses as responses, or something happens after that wipes that response out?</p>