我想使用纽约时报畅销书列表API来列出当前在HTML中的前20位 - 我设法检索数据使用AJAX(我可以看到它使用开发人员工具),但一直试图让它显示在页面上。我没有收到任何错误消息 - 没有任何反应。这是我的代码原因:无法获取JSON数据从Ajax请求显示在HTML
<!DOCTYPE HTML>
<html>
<head>
<title>Discover Books</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta charset="UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.js"></script>
<div id='books'>
</div>
</head>
<script>
$(document).ready(function(){
$.ajax ({
type: 'GET',
dataType: 'json',
url: 'http://api.nytimes.com/svc/books/v3/lists/hardcover-fiction?api-key=*API_KEY*',
success: function(response){
console.log(response);
for(var i = 0; i < response.length; i++) {
var listing = response[i];
$('#books').append('<h3>' + title + '</h3>');
}
},
error: function(xhr, status, error){
console.log(status);
console.log(error);
}
});
})
</script>
</html>
任何提示,我做错了什么? 谢谢
它是否默认为错误功能? – Derek
不要把你的API密钥放在代码示例中。我不知道这个API如何工作,但它通常是一个坏主意。 – dan08