不將模式添加為“no-cors”:
錯誤:APICALL.html:1 訪問從源“null”獲取“http://url”已被 CORS 策略阻止:對預檢請求的回應未通過訪問控制檢查:否“Access-Control-Allow-” Origin' 標頭存在于請求的資源上。如果不透明的回應滿足您的需求,請將請求的模式設定為“no-cors”以獲取禁用 CORS 的資源。
我已將模式添加為“no-cors”,但隨后我收到另一個錯誤請求錯誤。
錯誤:APICALL.html:66 POST http://url net::ERR_ABORTED 400(錯誤請求)
代碼 :
var data = {
Name: "Test",
Category: "Test-Category",
Mobile: "999999999999",
Email: "[email protected]",
Question: "Test Question",
};
var options = {
method: "POST",
mode: "no-cors",
origin: "*",
cache: "no-store",
headers: {
"Cache-Control": "no-store",
"Content-Type": "application/json",
},
body: data,
};
fetch("http://url", options)
.then((data) => {
if (!data.ok) {
throw Error(data.status);
}
return data.json();
})
.then((update) => {
console.log(update);
})
.catch((e) => {
console.log(e);
});
uj5u.com熱心網友回復:
中文因為存在跨域情況,需要你允許服務器開啟跨域,允許跨域訪問。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/422465.html
標籤:
