[英]How to fetch the data from the url if the response coming is opaque. mode: "no-cors" is not showing any effect
在獲取鏈接響應時應該給我一個包含兩個值的數組,但這里的響應顯示如下。
控制台響應:Response {type: "opaque", url: "", redirected: false, status: 0, ok: false, ...}
index.js:1 Error: Error: Could not fetch user roles data!
at fetchData (role-actions.js:12)
at async role-actions.js:21
**code:**
export const fetchRoleData = () => {
return async (dispatch) => {
const fetchData = async () => {
const response = await fetch("https://api.saaspect.com/user/roles", {
mode: "no-cors",
});
console.log("response", response);
if (!response.ok) {
throw new Error("Could not fetch user roles data!");
}
const data = await response.json();
return data;
};
try {
const roles = await fetchData();
console.log("inside try");
dispatch(
uiActions.showUserRoles({
userRoles: roles.items || [],
})
);
} catch (error) {
console.error("Error:", error);
}
};
};
你不能。 不透明意味着響應是一個你在里面看不到的盒子。
mode: 'no-cors'
僅在您需要發送請求而看不到響應時才有用。
如果你想查看它,你需要mode: 'cors'
和來自服務器的權限(根據 CORS 規范)來讀取響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.