开发者

XMLHttpRequest problem

开发者 https://www.devze.com 2022-12-26 18:32 出处:网络
I am trying to do "POST" with XMLHttpRequest in a firefox extension, and after that I try to get the "Location" header and open it in a new tab. For some reason, the XMLHttpRequest

I am trying to do "POST" with XMLHttpRequest in a firefox extension, and after that I try to get the "Location" header and open it in a new tab. For some reason, the XMLHttpRequest doesn't contain a location header.

My code

function web(url,request)
{
    var http = new XMLHttpRequest();
    http.open('POST',url,true);
    http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    http.onreadystatechange=function() {
    if(http.readyState == 2) {
        alert(http.getResponseHeader("Location"));
        }
 开发者_JAVA技巧   }
    http.send(request);
}

Also, if I change the alert to getAllResponseHeaders() to see all headers, I just don't see the location header there. If I try to spy on the request of the original site with Firebug, it does show me the location header in the response. Please help me resolve my issues. Thanks :)

P.S. I'm also unable to open a link in new tab using window.open(url, this.window.title);, but as that's not directly related to the rest of this I'll post a separate question to ask about it.


I think that current implementations of XHR are Location: agnostic. In other words, since XHR transparently follows HTTP redirects in a manner that is invisible to your code, I suspect that the whole XHR ball of wax has been made Location: agnostic and that the header is simply being stripped out.

[edit] Actually, now that I think of it, if XHR is following the redirect, then wouldn't it be the headers of the response to the redirect that you're seeing, and not the headers of the redirect itself?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号