Home » Categories » jQuery

How to get Response Header location from jQuery Get?

for some headers in jQuery Ajax you need to access XMLHttpRequest object

var xhr;
var _orgAjax = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function () {
  xhr = _orgAjax();
  return xhr;
};

$.ajax({
    type: "GET",
    url: 'http://example.com/redirect',
    success: function(data) {
        console.log(xhr.responseURL);
    }
});

or using plain javascript

var xhr = new XMLHttpRequest();
xhr.open('GET', "http://example.com/redirect", true);

xhr.onreadystatechange = function () {
  if (this.readyState == 4 && this.status == 200) {
    console.log(xhr.responseURL);
  }
};

xhr.send();

Refrence:
https://stackoverflow.com/questions/11223946/how-to-get-response-header-location-from-jquery-get/41929637#41929637
Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
Hidden image after redirect by check filename
Viewed 514 times since Wed, Sep 30, 2020
Attribute Contains Selector [name*=”value”]
Viewed 735 times since Wed, Sep 30, 2020
How to apply style to parent if it has child with CSS?
Viewed 465 times since Thu, Oct 8, 2020
jQuery multiple events to trigger the same function
Viewed 462 times since Mon, Sep 28, 2020