'How to check CORS Preflight response status code in js?
Is there any way to get a status code of a CORS Preflight response? Preflight response
I would like to make a condition for status of Preflight request.
The code I have right now:
let requestInCheck = new XMLHttpRequest();
requestInCheck.open("GET", "http://google.COM/", true); //CORS
requestInCheck.setRequestHeader('Cache-Control', 'no-cache');
requestInCheck.timeout = TIME_OUT;
requestInCheck.onerror = () => {
console.log(`There was an error while trying to make the request [STATUS: ${requestInCheck.status}]`);
serviceAcception = false;
this.setState({ serviceAcception });
}
requestInCheck.onload = () => {
console.log(`The response code is [STATUS: ${requestInCheck.status}]`);
if(requestInCheck.status !== 0)
serviceAcception = true;
this.setState({ serviceAcception });
} //...send method is below
Since the request is unable to be responded correctly, "onerror" is called and respectful message is logged: Console
Is there a way I can get preflight status code into some variable or smth?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
