Created
January 17, 2013 02:54
-
-
Save jzerbe/4553134 to your computer and use it in GitHub Desktop.
create a Cross Origin Resource Sharing enabled request
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) { | |
xhr.open(method, url, true); | |
} else if (typeof XDomainRequest != "undefined") { | |
xhr = new XDomainRequest(); | |
xhr.open(method, url); | |
} else { | |
xhr = null; | |
} | |
xhr.setRequestHeader("Content-Type", "application/json"); | |
return xhr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment