Wednesday, January 30, 2013

CORS without preflight

I had some trouble getting a CORS request to fire without preflight I finally got it and here it is In raw javascript:
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET", "http://jira/rest/api/latest/issue/DEV-793", false);
  xmlhttp.send();
  //exception (as expected) for 401 response from that site
  document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
since the server is not responding with the proper response header the browser won't let me read the response for security reasons, but at least the send side is working currently. This also works for send (still has the issue with the browser blocking the response from the javascript:
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.open("GET", "http://jira/rest/api/latest/issue/DEV-793", false);
  xmlhttp.setRequestHeader("accept", "application/json");
  xmlhttp.send();
  document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
I can't get jQuery to do it in Chrome whatsoever. Posted a SO question. Perhaps this is the problem, a bug in chrome Also I've found that I don't need to muck with the server if I set the command line option for chrome `http://stackoverflow.com/a/13154327/57883`

No comments:

Post a Comment