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

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

    }
}

这里我将 fetchmode:'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],因为您使用 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 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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