title: How to get response status code from jQuery.ajax?
body: <p>In the following code, all I am trying to do is to get the HTTP response code from a jQuery.ajax call. Then, if the code is 301 (Moved Permanently), display the 'Location' response header:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
    &lt;title&gt;jQuery 301 Trial&lt;/title&gt;
    &lt;script src="http://code.jquery.com/jquery-1.5.1.min.js"&gt;&lt;/script&gt;
  
    &lt;script type="text/javascript"&gt;
    function get_resp_status(url) {
      $.ajax({
        url: url,
        complete: function (jqxhr, txt_status) {
          console.log ("Complete: [ " + txt_status + " ] " + jqxhr);
          // if (response code is 301) {
          console.log ("Location: " + jqxhr.getResponseHeader("Location"));
          // }
        }
      });
    }
    &lt;/script&gt;
    &lt;script type="text/javascript"&gt;
    $(document).ready(function(){
      $('a').mouseenter(
        function () {
          get_resp_status(this.href);
        },
        function () {
        }
      );
    });
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;a href="http://ow.ly/4etPl"&gt;Test 301 redirect&lt;/a&gt;
    &lt;a href="http://cnn.com/not_found"&gt;Test 404 not found&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Can someone point out where I am going wrong? When I check the 'jqxhr' object in Firebug, I can't find the status code, nor the 'Location' response header. I set the breakpoint on last line of 'complete'.</p>
  
  <p>Thanks much.</p>