I am new to javascript. How can I add mode: 'no-cors' to my XMLHttpRequest in javascript? For example, to this code:
var xhr = new XMLHttpRequest();
xhr.open("POST", yourUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
value: value
}));
XMLHttpRequest does not support no-cors mode, only fetch does.
However, you are trying set a Content-Type of application/json which requires permission from CORS, so you can't use no-cors mode anyway.
If you used fetch and set no-cors mode then the instruction to set the Content-Type would be ignored.
Instead, configure yourUrl to grant permission, using CORS, to make the request with the JSON Content-Type.