我正在学习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.
})