【发布时间】:2020-12-24 14:08:28
【问题描述】:
我正在使用 fetch 通过 GET 请求读取一些数据。
类似这样的:
fetch(
'myurl.com/data',
requestOptions
)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log('error', error));
我在邮递员中测试过,它工作正常,它返回数据。
问题是当我在浏览器中调用它时,它返回的是 HTML 而不是 JSON。
在 Dev Tools -> Network -> Initiator 中,url 看起来不同,它在开头添加了“localhost...”
像这样:http://localhost:3000/store/orders/myurl.com/data。正因为如此,url 被破坏了,它不返回 JSON。
项目中没有http://localhost:3000/store/orders,在package.json这一行:"homepage": "/store/orders/"。
有没有办法解决这个问题?
【问题讨论】:
-
myurl.com的确切值是多少? -
使用
http://myurl.com/data没有myurl.com/data -
在网址前添加
http://或https://
标签: javascript reactjs localhost fetch package.json