javascript - 在 React 应用程序中获取 - 如何处理不透明的响应
问题描述
我对 React 和 JS 很陌生,试图从我的 React 组件中的服务获取数据,但没有任何内容:
fetch("http://localhost:9000/someEndPoint",
{
method: "GET",
mode: "no-cors",
credentials: "same-origin",
cache: "no-cache",
headers: {
"Accept" : "application/json; charset=utf-8",
"Content-Type" : "application/json; charset=utf-8"
}
})
.then((response) => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
})
.then((b) => {
console.log(b);
})
.catch((error) => {
console.log(error);
});
更新:由于 no-cors 模式,我得到一个不透明的响应,知道如何处理这个问题吗?
解决方案
推荐阅读
- react-native - 当人们使用 React Native 应用程序拍照时如何给出指导?
- android - 如何解决错误:Android Studio 中的非法字符:'\ufeff'
- awk - 如何在 awk 中搜索 '$(TARGET)?
- python - vairable 不会通过 python 传入 mysql
- python - Django 当我创建一个用户时,创建了一个数据库
- javascript - 我的验证不适用于我的动态输入
- vba - 如何在 VBA 中刷新数据透视表
- docker - ./downloadFabric.sh 意外故障地址 0x183e42838582
- json - 何时使用类对象或 json 字符串进行 http 请求
- r - 错误对象“。” 使用管道时找不到