I am trying to create a site that takes information form a music forum by searching an artist name and populates the artist 5 top albums, by popularity, number of tracks and release date. The information is pulling correctly from the site but when I go to create and HTML table no information is displayed. Search button is function properly, its calling all the right information, can help provide a solution in which I can extract the information from the array and populate/ create a table in HTML? below is the code I am currently working with.
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>
I Really want to understand whats going wrong here.