我试图创建一个网站,通过搜索艺术家的名字从音乐论坛中获取信息,并按流行度、曲目数量和发布日期填充艺术家的5张顶级专辑。信息是正确的从网站拉取,但当我去创建和HTML表没有显示任何信息。搜索按钮功能正常,它调用所有正确的信息,可以帮助提供一个解决方案,其中我可以从数组中提取信息,并在HTML中填充/创建表?下面是我目前正在使用的代码。
function searchClicked() {
var artist_name = document.getElementById("artistName").value;
var data = {};
data.ArtistName = artist_name
$.ajax({
type: "POST",
url: "/Home/SearchAlbum",
data: JSON.stringify(data),
success: function (responseData) {
debugger;
function writeTable() {
var html = ''
for (var i = 0; i < responseData; i++)
html += '<tr>';
for (var j = 0; j < totalCells; j++) {
html += '<td>' + array[count] + '</td>';
count++;
}
html += '</tr>';
}
$('#body').append(html);
count = 0;
},
contentType: "application/json; charset=utf-8",
})table {
width: 100%
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
table#artistName tr:nth-child(even) {
background-color: aquamarine
}
table#artistName tr:nth-child(odd) {
background-color: aquamarine
}
table#artistName th {
background-color: black;
color: white;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="jumbotron">
<p> Enter Artist Name:</p>
<input id="artistName" type="text" />
<button id="seachButton" onclick="searchClicked()">seach</button>
</div>
<table id="ALbumInfo">
<thead>
<tr>
<th>Album Name </th>
<th>Release Date</th>
<th>Popularity</th>
<th>Number of Tracks</th>
</tr>
</thead>
<tbody></tbody>
</table>
我真的很想知道这里出了什么问题。
https://stackoverflow.com/questions/51752725
复制相似问题