3

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();

// Refused to get unsafe header "Location"
// Error: NETWORK_ERR: XMLHttpRequest Exception 101
Treviño
  • 2,999
  • 3
  • 28
  • 23

2 Answers2

4

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.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Kinlan
  • 16,315
  • 5
  • 56
  • 88
  • Your language is a bit weird when talking about the W3C Access Control specification. You're also referring to a non existing header (`Access-Control-Allow-Max-Age`) while you actually meant to talk about `Access-Control-Allow-Origin`. – Bruce van der Kooij Sep 11 '10 at 07:33
  • Fixed it for you (and people coming after) – mplungjan Apr 28 '11 at 18:04
1

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

Mohamed Mansour
  • 39,445
  • 10
  • 116
  • 90