Last active
August 29, 2015 13:57
-
-
Save lmmx/9854833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createCORSRequest(method, url) { | |
var xhr = new XMLHttpRequest(); | |
if ("withCredentials" in xhr) { | |
// Check if the XMLHttpRequest object has a "withCredentials" property. | |
// "withCredentials" only exists on XMLHTTPRequest2 objects. | |
xhr.open(method, url, true); | |
} else if (typeof XDomainRequest != "undefined") { | |
// Otherwise, check if XDomainRequest. | |
// XDomainRequest only exists in IE, and is IE's way of making CORS requests. | |
xhr = new XDomainRequest(); | |
xhr.open(method, url); | |
} else { | |
// Otherwise, CORS is not supported by the browser. | |
xhr = null; | |
} | |
return xhr; | |
} | |
// define an XML link | |
var xhr = createCORSRequest('GET', xmlLink); | |
if (!xhr) { | |
throw new Error('CORS not supported'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment