Skip to content

Instantly share code, notes, and snippets.

@jzerbe
Created January 17, 2013 02:54
Show Gist options
  • Save jzerbe/4553134 to your computer and use it in GitHub Desktop.
Save jzerbe/4553134 to your computer and use it in GitHub Desktop.
create a Cross Origin Resource Sharing enabled request
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