test4 = () => {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var xmlDoc1 = xhr.responseText;
console.log("?", xmlDoc1)
}
xhr.open("GET",'http://www.naver.com');
xhr.open("Access-Control-Allow-Origin",'http://www.naver.com');
xhr.send();
}
}
componentDidMount() {
this.test4()
}
error ==> XMLHttpRequest cannot load http://www.naver.com/. Response for preflight is invalid (redirect) please help me...
There are a few problems here. Primarily though, CORS is preventing you from doing an XHR to www.naver.com. Unless you have some way to tell
www.naver.com
to allow you to make these types of requests, then you can't from a browser client.First, the
.open
method is not used to add headers to a request. Second,Access-Control-Allow-Origin
is a response header not a request header. It would make very little sense for the client to be able to declare the permitted access control to the server. Ref: MDN