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 ID: 42
Created On: Wed, Sep 30, 2020 at 7:09 AM
Last Updated On: Wed, Sep 30, 2020 at 7:09 AM
Authored by: Saeed Nobakht [[email protected]]

Online URL: https://www.navel.ir/article/how-to-get-response-header-location-from-jquery-get-42.html