Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top