我正在學習 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.
})
uj5u.com熱心網友回復:
這是一個預檢請求
通過傳遞正確的 CORS 標頭來處理選項請求。
然后還要處理發布請求,由于 API 和網站的新 CORS 標準,這兩個請求都是必需的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/357670.html
標籤:javascript 接口 http 邮政 拿来
