ora*_*ora 2 javascript fetch express
我正在使用express、fetch 和firefox。这是代码
async updateTutorial() {
const requestOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(this.currentTutorial)
};
await fetch("https://localhost:9000/tutorial/update" , requestOptions);
}
Run Code Online (Sandbox Code Playgroud)
在 Firefox 中,我看到此错误: TypeError: NetworkError 当尝试获取资源时我不知道这是什么类型的问题。
首先,你必须使用http而不是https。
要修复 cors 错误,您必须mode:"no-cors"在请求选项中指定。
async updateTutorial() {
const requestOptions = {
method: "POST",
mode: "no-cors",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(this.tutorial)
}
await fetch("http://localhost:9000/tutorial/update" , requestOptions);
}
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助。如果您遇到任何问题,请告诉我。
| 归档时间: |
|
| 查看次数: |
22737 次 |
| 最近记录: |