【发布时间】:2021-12-27 18:45:02
【问题描述】:
我正在学习 JavaScript,我正在制作一个帐户登录页面作为学习项目。服务器正在使用 Python 的 Flask。 fetch 功能似乎没有像我想要的那样工作。一方面,它发送的是选项请求而不是 POST,即使我指定了 POST。另一件事是服务器没有收到数据,它显示为空白。代码如下:
var content = JSON.stringify({'username': username, 'password': password}) //username and password are user inputs, I had them print and these work fine.
var response = fetch(url+"/api/login", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: content
})
.then(response => {
console.log("Success") //this doesn't print.
})
【问题讨论】:
-
听起来您正在进行跨域调用。它在发布之前进行握手。
标签: javascript api http post fetch