简体   繁体   English

成功获取api但没有回应

[英]successful fetch of api but no response

I am fetching a url using fetch in react redux application which looks like: 我正在使用反应redux应用程序中的fetch获取一个URL,如下所示:

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: 当我调用url时,它被调用,响应为200.当我在控制台中看到响应时,我从url得到了正确的响应但是response.status给了我0并且我的response看起来很奇怪:

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

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. 我不知道这里有什么问题,因为我的api被调用,甚至我得到了回应,但我无法得到回应。

Is it I have to wait for api to complete and process further? 我是否必须等待api完成并进一步处理? 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. 没有HTTP状态代码0.您看到的是您正在使用的库返回的0。 You will have to check the documentation for that. 您必须检查文档。

Try sending mode: 'cors' 尝试发送模式:'cors'

in no-cors mode you will gat an opaque response 在无人模式下你会得到一个不透明的回应

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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