Javascript Set Header Access-control-allow-origin
I'm testing JS with POST. But I didn't get success with that. Using the code:
testing js...
Solution 1:
Look at the XHR response: Access-Control-Allow-Origin IS present, Origin is null because you are executing it from your local system, upload to a server to see origin populated.
functionupload() {
var method = "POST";
var url = "http://127.0.0.1:9000/push";
var xhr = newXMLHttpRequest();
xhr.open(method, url);
xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
var text = {"command":"PUSH"};
xhr.send(text);
}
$(document).ready(function(){
$('.upload').click(upload);
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttonclass="upload">Upload</button>
Post a Comment for "Javascript Set Header Access-control-allow-origin"