admin管理员组文章数量:1277910
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
}));
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
}));
Share
Improve this question
edited Oct 12, 2022 at 15:00
Yves M.
31k24 gold badges109 silver badges149 bronze badges
asked Aug 16, 2021 at 10:01
разия Утегеноваразия Утегенова
831 gold badge1 silver badge9 bronze badges
1
- Does this answer your question? stackoverflow./questions/14667512/… – Adil Bimzagh Commented Aug 16, 2021 at 10:05
1 Answer
Reset to default 7XMLHttpRequest
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
.
本文标签: javascriptHow to add mode 39nocors39 to XMLHttpRequestStack Overflow
版权声明:本文标题:javascript - How to add mode: 'no-cors' to XMLHttpRequest? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741221895a2361117.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论