Skip to content

Instantly share code, notes, and snippets.

@rmruano
rmruano / Cross-browser XHR for CORS requests
Created January 25, 2013 21:31
Simple Cross-browser XHR request with Cors support. Supported by any moder browser and IE>=8.
newCorsXHR = function(type, url) {
var xhr = false;
try {
xhr = new XMLHttpRequest();
} catch(e) {}
if (xhr && "withCredentials" in xhr) {
xhr.open(type, url, true); // Standard Cors request
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest(); // IE Cors request
xhr.open(type, url);