首页 > 解决方案 > 无法在网页上查看 JS API 响应

问题描述

首先,我对使用 API 和 JS 非常陌生。

我使用 PostMan 创建了以下获取请求,它在 JSON 响应中完美地返回了预期结果。

<script>
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://www.reed.co.uk/api/1.0/search?keywords=construction&location=sheffield",
  "method": "GET",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic NWFmZTBmOTAtMzQ4MC00ZDQ3LTgyMDYtMzUyOTgxNWE2MTBhOg==",
    "User-Agent": "PostmanRuntime/7.17.1",
    "Accept": "*/*",
    "Cache-Control": "no-cache",
    "Postman-Token": "f69f3ecb-2e0c-4fcc-9cfa-796115805319,6cd343e2-d8d8-412e-b505-34218c69adca",
    "Accept-Encoding": "gzip, deflate",
    "Cookie": "__cfduid=d569febd387dab8f972be1c6b2e2bd4341570112246; jsSplitTestGroup=8; .ASPXANONYMOUS=DF9G8b4OJy1PLMCJfQ-MY2TYySziRwo3Bm2dh7UcE9XCMvpkGsIREQYCT0qhS28zfqtWcBrGFmyOWNvp7xrMpdntsx8vldDCHlF15cGeN8eqL4-iyRTCsBFEWaLYnFGpHT7Biw2",
    "Referer": "http://www.reed.co.uk/api/1.0/search?keywords=construction&location=sheffield",
    "Connection": "keep-alive",
    "cache-control": "no-cache"
  }
}

$.ajax(settings).done(function (response) {
  console.log();
});
</script>

现在,当我将其粘贴到我的 .html 页面中时,没有显示任何响应,控制台中也没有显示错误。

如何在网页上呈现 JSON 响应?

提前谢谢了

标签: javascriptajaxapi

解决方案


推荐阅读