title: How to get the final URL after an Ajax redirect?
body: <p>I am working on an AJAX script that makes a GET request to a shortened URL, like a bit.ly link. How do I actually get the URL of the final/redirected page?</p>
  
  <p>I can get the response headers from the redirected page, but it doesn't appear to contain the URL information:</p>
  
  <pre><code>$.ajax({
    url: "http://www.thislinkredirects.com",
    success: function(data, status, xhr) {
      var response = $(data);
    },
    complete: function(xhr) {
      console.log(xhr.getAllResponseHeaders());
    }
  });
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Date: Tue, 23 Jun 2015 03:22:07 GMT
  Allow: POST, GET, OPTIONS, PUT, DELETE
  Server: lighttpd/1.4.35
  X-Powered-By: PHP/5.3.3
  Transfer-Encoding: chunked
  Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
  Content-type: text/html
  Access-Control-Allow-Origin: *
  Access-Control-Allow-Headers: accept, authorization
  </code></pre>
  
  <p>I do not have control of the server making the get request.</p>