Closed gregglind closed 8 years ago
cors:
function cors1 (url, method, data) { return new Promise(function (resolve, reject) { var createCORSRequest = function(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { // Most browsers. xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { // IE8 & IE9 xhr = new XDomainRequest(); xhr.open(method, url); } else { // CORS not supported. xhr = null; } return xhr; }; console.log("creating", method, url) var xhr = createCORSRequest(method, url); xhr.onload = function() { // Success code goes here. console.log("OK") resolve("OK") }; xhr.onerror = function() { // Error code goes here. console.error("NOPE") reject("nope"); }; console.log("data:", data); // now break it... xhr.setRequestHeader("Content-Type", 'application/json'); xhr.send(JSON.stringify(data)); }) }
The setRequestHeader line breaks things. Removing it from request gives a 415 error instead.
see https://gist.github.com/gregglind/f8a2a3f9664ad1b59cbc for alt cors impl.
Problem was: http/2
cors:
The setRequestHeader line breaks things. Removing it from request gives a 415 error instead.