HEAD XMLHttpRequest for Chrome

I am trying to get a HEAD response with XMLHttpRequest in Chromium to extract 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(); // Refused to get unsafe header "Location" // Error: NETWORK_ERR: XMLHttpRequest Exception 101 
+2
source share
2 answers

As Mohamed pointed out, you will need to create a proxy service on the same site on which your page is hosted, since this is a request for a cross-domain domain.

This should fail in all browsers unless you explicitly allow cross-domain requests in your browser. If bit.ly supported cross-domain requests through the W3C specification for Access-Control-Allow-Origin, then your code will work.

+4
source

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

+1
source

All Articles