使用提取错误,响应似乎为空

时间:2020-05-09 08:27:27

标签: javascript angular typescript fetch

我正在使用访存来从我的api中检索数据,根据日志返回的响应是:

def getPercent(past: float, current: float):
    eps = 1e-9
    p = ((current - past + eps) / (past + eps)) * 100 # considering past is never - eps
    return round(p, 2)

但在调试时成角度:

{
    "statusCode": 200,
    "headers": {
        "Content-Type": "application/json"
    },
    "body": "[{\"text\": \"1\", \"email\": \"test1@asfsaf.com\"}, {\"text\": \"3\", \"email\": \"test3@asfsaf.com\"}, {\"text\": \"2\", \"email\": \"test2@asfsaf.com\"}]"
}

我用来调用api的代码是:

body: null
bodyUsed: false
headers: Headers {append: function, delete: function, get: function, has: function, set: function, …}

ok: false

redirected: false

status: 0

statusText: ""

type: "opaque"

url: ""

组件上的代码:

getLastReviews()
  {
    return fetch (
        ApiService.url ,
        {
          headers: {
            'Content-Type': 'application/json',
          },
          method: 'GET',
          mode: 'no-cors',
        }, 
      )
  }

我尝试使用邮递员调用此url,尽管在浏览器中输入url时,我也得到一个空的响应-{},但它没有错误。 有谁知道问题可能在哪里?谢谢!

0 个答案:

没有答案