Working on that problem, I wrote the following script:
window.onload = function() {
var request = new XMLHttpRequest();
var url = "http://localhost:3000/say_hello";
var params = "username=FooMan";
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
console.log(request.responseText);
}
}
request.open("POST", url, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.withCredentials = true;
request.send(params);
}
However every time I try to execute that script I'm getting
XMLHttpRequest cannot load http://localhost:3000/say_hello. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I've tried using
request.setRequestHeader("Access-Control-Allow-Origin", "*");
request.setRequestHeader("Access-Control-Allow-Origin", "hello.html");
The browser is Chrome
. What am I doing wrong or missing?