我用下面的代码调用一个API,如果我得到的只是对象对象。我试过一些不同的方法,但没有成功。我正在获取jquery-3.4.1.min.js:2xhr已完成加载:在控制台中获取“url.to.api”。这是我的密码。
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="./jquery-3.4.1.min.js"></script>
<title></title>
</head>
<body>
<script>
$.ajax({
type: "GET",
url: "to API", // note, this doesn't end in JSON, but if I type the URL into my browser, I can view the JSON data
// Request headers
beforeSend: function(xhrObj) {
xhrObj.setRequestHeader("Cache-Control", "no-cache");
xhrObj.setRequestHeader("Subscription-Key", my key");
},
})
.done(function (data) {
alert(data); // I changed this from a 'success' pop up to tell me it was working, but I can't display the data anywhere, so I tried in the box, and got object object
})
.fail(function () {
alert("error");
});
</script>
</body>
</html>
我是API的新手,这方面根本没有文档。谢谢!