2

This answer says that the XmlHttpRequestObject Level 2 supports cross-site ajax calls. I know a lot of browsers are supporting a lot of HTML5 features. Is this something Chrome or Firefox (or by some miracle IE) supports?

If so, does jQuery offer a way to utilize it when using the $.ajax method?

Community
  • 1
  • 1
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393

1 Answers1

2

Yes, browsers such as Firefox > 3.5 and Safari > 4, Chrome > 3 support XmlHttpRequestObject Level 2, IE 8 has its own separate XDomainRequest. Despite this, the other side (that you are requesting data from) must allow the data to be accessed in such a manner (through something called CORS), so you cannot make cross-domain requests to just any arbitrary domain. This might be fine if you are making a request to some compliant remote API, but this is not always the case.

This being said, I wouldn't recommend cross-domain AJAX as I cannot really see the benefits it provides. Browser locking can be prevented by using an AJAX proxy (a regular HTTP request to the remote domain is carried out by the server and the result is returned via an AJAX call). A lot of popular browsers do not support cross-domain AJAX either (IE 6, IE 7, no version of Opera), so you are creating a lot of compatibility issues.

As part of your question asked for an example, here's an article on how to achieve this, including a little demo. It includes the file cors.js which seems to be cross-browser cross-domain AJAX compliant.

Uku Loskit
  • 40,868
  • 9
  • 92
  • 93
  • Thanks for your answer. The main reason I care so much is because I've done some work with Amazon WS, and they limit you to one request / IP, so if everything is going through your own proxy, then if you ever get popular and exceed that, you'd have some dropped requests. Of course cross-domain works with Silverlight, but I much prefer javascript/html5. – Adam Rackis Aug 17 '11 at 20:05
  • 1
    So if you're using a suitable browser, with jQuery be smart enough to use an XHR Level2 object for you??? – Adam Rackis Aug 17 '11 at 20:07