redux fetch body is not use with no cors mode(redux fetch body 在没有 cors 模式的情况下不使用)
问题描述
我有这个调用函数的动作:
I have this action which calls a function:
dispatch(Api({url: "my_url", method: "POST", data: data}))
这里我将数组作为数据传递..
Here I am passing array as a data..
import fetch from 'isomorphic-fetch'
export default function Api({url, method, headers, data}={}){
return dispatch => {
console.log(data)
console.log(url)
console.log(method)
console.log(JSON.stringify(data))
let response = fetch(url, {
mode: 'no-cors',
method: method || null,
body: data || null,
}).then(function(response) {
console.log("response");
console.log(response)
});
}
}
我在这里使用 fetch
和 mode:'no-cors'
我想我传递了所有的争论.我的身体是我传递的简单数组作为争论..
Here I am using fetch
with mode:'no-cors'
I guess I am passing all the arguements.. My body here is simple array that I am passing as arguement..
当我看到回复时,就像:
When I see the response it is like :
body: null
bodyUsed: false
headers: Headers
ok: false
status: 0
statusText: ""
type: "opaque"
url:""
这里我的身体没有被使用..
Here my body is not being used..
这里有什么问题?需要帮助
What is wrong in here ? Need help
推荐答案
你得到一个不透明的响应
[1] [2],因为您将 fetch 与 mode: 'no-cors'
一起使用.您需要使用 mode: 'cors'
并且服务器需要发送所需的 CORS 标头 [3] 以访问响应.
You're getting an opaque response
[1] [2], because you're using fetch with mode: 'no-cors'
.
You need to use mode: 'cors'
and the server needs to send the required CORS headers [3] in order to access the response.
这篇关于redux fetch body 在没有 cors 模式的情况下不使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:redux fetch body 在没有 cors 模式的情况下不使用


基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01