redux fetch body不能用于没有cors模式 [英] redux fetch body is not use with no cors mode

查看:159
本文介绍了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)
            });

    }
}

我在这里使用使用获取模式:'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的回复 [ 1 ] [ 2 ],因为您使用模式获取:'no-cors'
您需要使用模式:'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模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆