简体   繁体   中英

successful fetch of api but no response

I am fetching a url using fetch in react redux application which looks like:

fetch(url, {
            mode: 'no-cors',
            method: method || null,
            headers: headers || null,
            body: form || null,
            }).then(function(response) {
                console.log(response.status)
                console.log("response");
                console.log(response);
            }).then(function(data){
                console.log(data)
                console.log(data)
            })

Strange this is happening. When I call the url it is called and the response is 200. When I see in the console for response I am getting proper response from the url but response.status is giving me 0 and my response looks weird like:

body: null ok: false and so on...

I don't know what is wrong in here because my api is called and even I am getting response but I am unable to catch the response.

Is it I have to wait for api to complete and process further? Like waiting for fetch if yes then how can I do it?

There is no HTTP status code 0. What you see is a 0 returned by the library that you are using. You will have to check the documentation for that.

Try sending mode: 'cors'

in no-cors mode you will gat an opaque response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM