0
首先,我是Javascript,Ajax,jQuery,JSON和开发世界的新成员。我正在研究一个我想要显示Google Books API搜索结果的Web项目。目前我做了只显示1个结果的代码,并且它工作正常,但是我在console.log中看到API显示了一个包含10个项目的数组,因此我想显示它们。我想显示所有这些结果,但我不知道如何执行此操作。 我在HTML代码有一个DIV,这是我的Ajax代码使用Ajax显示API的更多搜索结果
$.ajax({
url: API + libroBuscado,
success: function(data) {
var componente = `<div class="card" style="width: 20rem;">
<div class="card-body">
<h4 class="card-title">Card title</h4>
<h4 class="precio">$</h4>
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="card-link">Descarga un adelanto</a>
<a href="#" class="card-link">Comprar</a>
</div>
</div>`;
var titulo = data.items[0].volumeInfo.title;
var venta = data.items[0].saleInfo.saleability;
var precio = "ARS $" + data.items[0].saleInfo.listPrice.amount;
var autor = data.items[0].volumeInfo.authors;
var sinopsis = data.items[0].volumeInfo.description;
var descarga = data.items[0].accessInfo.webReaderLink;
var compra = data.items[0].saleInfo.buyLink;
$(".col-12").html(componente);
$(".card-title").text(titulo);
$(".precio").text(precio);
$(".card-subtitle").text(autor);
$(".card-text").text(sinopsis);
$(".card-link:nth-of-type(0)").attr("href" + descarga);
$(".card-link:nth-of-type(1)").attr("href" + compra);
console.log(data);
},
error: function(error) {
console.log(error);
}
});
});
我想作一个for循环,但我不知道该怎么做,或是否会工作