-2

我正在GET从我的服务器向第三方 API 发出请求。请求返回JSON响应。

现在我有了它JSON,我想从前端向服务器发出一个 fetch API 请求,以便检索它JSON并在前端显示它。

目前我的设置是这样的:

www.siteA.com/backend > This is a page on the backend.
It makes a request to a third party site that returns some json data
www.siteA.com/frontend > This is the front end of the site.
I make a fetch request to www.siteA.com/backend to retrieve the json data that
was returned from the backend api request to the third party site.

当我检查从 www.siteA.com/frontend 到 www.siteA.com/backend 的 fetch 请求中得到的响应时,它实际上是在接收整个 html 页面,而我只想要 JSON 数据。

如何从前端检索 json?

4

1 回答 1

0

您能否向我们提供更多信息?您是否只是在寻找一种从 API 获取数据的方法?如果是,我认为最简单的选择是使用该fetch()方法

    fetch('www.your-restapi.com/something-here')
      .then(res=> {
        return res.json()
      })
      .then(data => {
       // your data is available 
      })
于 2019-11-07T15:11:04.357 回答