Today I stumbled upon what seems to be a cross-dmain issue in IE when trying to obtain data from server at domain A to client at domain B through an XmlHttpRequest (XHR) using jQuery.ajax for coding convenience.

Servers disallow such requests by default and setting the Access-Control-Allow-Origin header will whitelist other domains (or all domains by setting its value to “*”).

I was working on an html/js page on my localhost debug environment and I tried to get content from our staging server at a different domain. The Access-Control-Allow-Origin header was set to “*” and I am doing the required requests by said jQuery ajax call. Everything works fine in Chrome and Firefox.

IE however gave an error without many details and after some googling it seems this was due to IE XmlHttpRequests not allowing cross-domain requests regardless of the server’s setting. Instead, one needs to use IE’s proprietary XDomainRequest.

All well and good, but I was surprised to find that jQuery doesn’t work around this. There’s a ghist that adds XDomainRequest support to jQuery so the solution to this problem was simple, but I found this discussion far more interesting:

Ticket #8283 BUILT-IN SUPPORT FOR XDOMAINREQUEST

In short, the discussion is about wether jQuery should offer built-in support for XDomainRequest or if it should be provided as a plugin. I agree with some of the posters that jQuery’s main use is two-fold:

  1. Work around browser inconsistencies
  2. Simplifying complex operations

To me, a difference in XHR implementation in regard to cross domain requests falls under the same category as working around the difference is setting up DOM event listeners, and jQuery should offer built-in support.

What do you think?

0

Comments

blog comments powered by Disqus