redux fetch body is not use with no cors mode

吃可爱长大的小学妹 提交于 2019-12-17 18:43:13

问题


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)
            });

    }
}

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:


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.



来源:https://stackoverflow.com/questions/35169728/redux-fetch-body-is-not-use-with-no-cors-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!