问题描述
我有一个调用函数的动作:
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)
});
}
}
我在这里使用使用
我想我正在传递所有的争论..我的身体在这里是简单的数组我我作为争论传递.. 获取
模式:'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
推荐答案
你得到一个 opaque的回复
[] [],因为您使用模式获取:'no-cors'
。
您需要使用模式:'cors'
并且服务器需要发送所需的CORS头[]以便访问回复。
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模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!