未在 html 页面上显示来自 API 的值,但正在加载 JSON
Not showing values from API on html page but loading the JSON
正在尝试从 soundcloud 中提取曲目列表 api。
- 歌曲一首
- 歌曲二
- 歌三
开始 json 返回:
但它没有在 html
中显示结果
继承人html:
<!DOCTYPE html>
<html>
<head>
<!-- bootstrap and js -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" title="bootstrap-css" charset="utf-8">
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!-- soundcloud info -->
<script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<ol id="track-list"></ol>
</body>
</html>
继承人 js:
SC.initialize({
client_id: "myid",
redirect_uri: "mycallback",
});
var userId = 39090345; // user_id of Prutsonic
SC.get("/tracks", {
user_id: userId,
limit: 100
}, function (tracks) {
var tmp = '';
for (var i = 0; i < tracks.length; i++) {
tmp = '<a href="' + tracks[i].permalink_url + '">' + tracks[i].title + ' - ' + tracks[i].duration + '</a>';
$("<li/>").html(tmp).appendTo("#track-list");
}
});
基于 API,您似乎应该将 }, function (tracks) {
更改为 }).then(function (tracks) {
。 API 希望您使用承诺。
SC.get("/tracks", {
user_id: userId,
limit: 100
}).then(function (tracks) {
var tmp = '';
for (var i = 0; i < tracks.length; i++) {
tmp = '<a href="' + tracks[i].permalink_url + '">' + tracks[i].title + ' - ' + tracks[i].duration + '</a>';
$("<li/>").html(tmp).appendTo("#track-list");
}
});
正在尝试从 soundcloud 中提取曲目列表 api。
- 歌曲一首
- 歌曲二
- 歌三
开始 json 返回:
但它没有在 html
中显示结果继承人html:
<!DOCTYPE html>
<html>
<head>
<!-- bootstrap and js -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" title="bootstrap-css" charset="utf-8">
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!-- soundcloud info -->
<script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<ol id="track-list"></ol>
</body>
</html>
继承人 js:
SC.initialize({
client_id: "myid",
redirect_uri: "mycallback",
});
var userId = 39090345; // user_id of Prutsonic
SC.get("/tracks", {
user_id: userId,
limit: 100
}, function (tracks) {
var tmp = '';
for (var i = 0; i < tracks.length; i++) {
tmp = '<a href="' + tracks[i].permalink_url + '">' + tracks[i].title + ' - ' + tracks[i].duration + '</a>';
$("<li/>").html(tmp).appendTo("#track-list");
}
});
基于 API,您似乎应该将 }, function (tracks) {
更改为 }).then(function (tracks) {
。 API 希望您使用承诺。
SC.get("/tracks", {
user_id: userId,
limit: 100
}).then(function (tracks) {
var tmp = '';
for (var i = 0; i < tracks.length; i++) {
tmp = '<a href="' + tracks[i].permalink_url + '">' + tracks[i].title + ' - ' + tracks[i].duration + '</a>';
$("<li/>").html(tmp).appendTo("#track-list");
}
});