prevent xhr from redirecting when response is 303 with location header

大兔子大兔子 提交于 2020-01-04 01:19:12

问题


I get a 303 response with a location header, how can I prevent XMLHttpRequest from redirecting?

Below is the code

var xhr = new XMLHttpRequest();

xhr.open('GET', '/api/v1/test' + $(e.target).data('machineimage'));

xhr.onreadystatechange = function () {
    if (xhr.readyState == 4) {
        // here I need to get the `location` header and do something with it
        // xhr.getResponseHeader('location')
        // but before it reaches here, there is a redirect
    }
};

xhr.send();

I observed its the same with jquery as well, is there anyway to bypass this?

来源:https://stackoverflow.com/questions/13420417/prevent-xhr-from-redirecting-when-response-is-303-with-location-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!