我正在尝试创建相册搜索,但无法进行ajax调用。我之前做过类似的项目,但它们工作得很好,但是在这里,ajax代码块没有被执行。有人可以解决这个问题吗?
这是我的代码:
$(document).ready(function() {
function getAlbum() {
var search = document.getElementById('search-box');
var results;
var html = "";
$.ajax({
url: "https://api.deezer.com/search/album/?q=" + search.value,
dataType: 'jsonp',
data: {
format: 'jsonp'
},
success: function(response) {
results = response.data;
var pgs = Object.keys[results];
pgs.forEach(function(page) {
var cover = results[page].cover;
var title = results[page].title;
var link_ = results[page].link;
html += '<div class="cover">' + '<a href=' + link_ + 'target="_blank">' + cover + '</a>' + '</div>' + '<div class="title">' + title + '</div>';
});
$('#output').innerHTML = html;
}
});
}
$('#search-icon').on('click', function() {
getAlbum();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="search-box" /><button id="search-icon">?</button>