/**
Returns a string with the iTunes data in table html format
**/
var appendValues = function(songArray) {
songArray.each(function() {
var title = $(this).find("im\\:name").eq(0).text();
var songImage = $(this).find("im\\:image").eq(0).text();
var artist = $(this).find("im\\:artist").text();
var album = $(this).find("im\\:collection").children().eq(0).text();
var sample = $(this).find("link").eq(1).attr("href");
$("#songs").append(
"" +
"" + title + "" +
"" + artist + "" +
"" + album + "" +
"
" +
"" +
"" +
"" +
"Your browser does not support the audio element." +
"" +
"");
});
}
/**
Gets top song list from iTunes. Accepts two parameters, country and songNumber, which are inserted into URL. Displays song list in HTML.
**/
var getSongs = function( country, songNumber ){
$.get("https://itunes.apple.com/" + country + "/rss/topsongs/limit=" + songNumber + "/xml", function(data){
var songArray = $(data).find("entry");
appendValues(songArray); //Function that adds values to html table
}, "xml");
}
/**
Gets user input from dropdown menu and slider. Calls getSongs function to update song list.
**/
var updateSongs = function(){
//Get country input
var country = $("#dropdown").val();
if (country == "united_states"){
country = "us";
} else if(country == "india"){
country = "in";
} else {
country = "tr";
}
//Get song number input
var songNumber = $("#slider").slider("value");
//Setup HTML table
$("#songs").append(
"iTunes Top Hits" +
"" +
"" +
"" +
"" +
"Select Country: " +
"" +
"United States" +
"India" +
"Turkey" +
"" +
"
" +
"Number of Songs: 10" +
"
" +
"" +
"" +
"" +
"" +
"" +
"Song Title" +
"Artist" +
"Album" +
"Album Cover" +
"Song Sample" +
""
);
setupSlider();
//Refresh song list
getSongs(country, songNumber);
}
var setupSlider = function(){
//Sets up the slider
$("#slider").slider({
orientation: "horizontal",
range: 5,
max: 30,
value: 10
//slide: updateText,
//change: updateText
});
}
var erase = function(){
$("#songs tr").remove();
}
$(document).ready(function(){
setupSlider();
var country = "us";
var val = $("#slider").slider("option", "value");
getSongs(country, val);
//On Update click, erase the old song list and update with current list.
$("#update").click(function() {
erase();
updateSongs();
});
});< /code>
table {
table-layout: fixed;
width: 75%;
margin: auto;
}
td {
word-wrap: break-word;
}
audio {
width: 100px;
text-align: center;
}
table, th, td {
border: 1px solid #c1c1c1;
border-collapse: collapse;
}
td, th {
padding: 5px;
font-family: Arial, sans-serif;
width: 100px;
}
caption {
font-family: Verdana, sans-serif;
font-weight: bold;
font-size: 1.2em;
padding-bottom: 5px;
}
tr:nth-of-type(even) {
background-color: #eaeaea;
}
tr:nth-of-type(2) {
background-color: black;
color: white;
}
td:nth-of-type(4) {
text-align:center;
}
td:nth-of-type(5) {
text-align:center;
}
#slider {
width: 150px;
}< /code>
iTunes Top Hits
Select Country:
United States
India
Turkey
Number of Songs: 10
Song Title
Artist
Album
Album Cover
Song Sample
< /code>
< /div>
< /div>
< /p>
У меня есть функция, которая делает вызов Ajax в iTunes и получает список песен, которые добавляются к таблице HTML, с кнопкой обновления, которая снова запускает ту же функцию. Я запускаю функцию, когда загружаю страницу, и все хорошо загружается, но когда я нажимаю обновление, функция пропускается. Я могу посмотреть его в Firefox Debugger, пройдя мимо этого. РЕДАКТИРОВАТЬ: Я добавил фрагмент кода, но он не отображается должным образом; однако проблема остается.
Подробнее здесь: https://stackoverflow.com/questions/341 ... econd-time