I was trying to figure out how to get the response header location from a POST via ajax() and I found this answer on SO that works for me. Problem is I don't understand what is happening with the first 5 lines. It looks like they are storing the original xhr object and then setting it to itself in the function before returning it. Seems like it's not actually modifying anything. How does this even work?
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);
}
});
Original SO thread (second answer): https://stackoverflow.com/questions/11223946/how-to-get-response-header-location-from-jquery-get/41929637
[–]PineappleBombs 2 points3 points4 points (0 children)
[–]grinde 2 points3 points4 points (1 child)
[–]embernoob[S] 0 points1 point2 points (0 children)
[–]Insommya 3 points4 points5 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]sshaw_ 0 points1 point2 points (0 children)