I was silly enough to believe that all modern browsers supported CORS
(Cross-Origin Resource Sharing).
When my toy JavaScript tool didn't work on IE9 or Opera I found out that the former only supported CORS
through XDomainRequest
, which jQuery doesn't seem to support. Opera doesn't support CORS
at all yet.
Now jQuery has an abstract interface that does normal same domain AJAX queries, CORS
queries, and even JSONP
queries the same way.
Is there an extension to this interface that goes further making it work even with XDomainRequest
and falling back to JSONP
when CORS
isn't available?
Here is a plugin for XDomainRequest support in JQuery:
https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js
There is also a jQuery feature request to add this feature:
http://bugs.jquery.com/ticket/8283
Note that the bug report says that there may be an issue with the plugin in IE9, so YMMV. It ended up getting closed with the reason given that the plugin exists to do the job.
Take a look at xReader:
<script src="http://kincrew.github.com/xReader/xReader.full.js"></script>
<script type="text/javascript">
xReader("http://www.yahoo.com/", function(data) {
alert(data.content);
})
</script>
It's simple!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With