开发者

HEAD XMLHttpRequest on Chromium

开发者 https://www.devze.com 2022-12-26 09:09 出处:网络
I\'m trying to get the HEAD response with an XMLHttpRequest in Chromium to retrive the location URL of a compressed url, but it fails:

I'm trying to get the HEAD response with an XMLHttpRequest in Chromium to retrive the location URL of a compressed url, but it fails:

var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() { if (ajax.readyState == 4) alert(ajax.getResponseHeader("Location")) };
ajax.open('HEAD', "http://bit.ly/4Agih5", false);
ajax.send();

//开发者_JAVA技巧 Refused to get unsafe header "Location"
// Error: NETWORK_ERR: XMLHttpRequest Exception 101


As Mohamed indicated, you will have to create a proxy service on the same site that you are hosting your page on as this is a cross domain request.

This should be failing in all browsers, unless you have explicitly allowed cross domain requests in your Browser. If bit.ly supported cross domain requests via the W3C spec for Access-Control-Allow-Origin then your code would work.


You cannot do cross-domain XHRs. Use a web programming language like JSP/Python/PHP/Ruby/etc..

0

精彩评论

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