问题是我的acceptData()函数将返回的数据附加到第一个元素#cast(让我们假装有4个#cast元素)。如何进行修改,以便所有数据不会仅附加到第一个元素,而是附加到4?
中的每一个 //retrieves data from ajax request
function searchCallback(data) {
$('#results').empty();
$('#results').scrollTop();
var results = data.searchResponse.results
for (i in results){
$('#results').append("<div id='movieTitle'>" + results[i].movie.title + "</div>" + "<div id='cast'>" + "</div>");
}
//check if cast result is null
if(results[i].movie.castUri != ""){
var cast = results[i].movie.castUri;
sendRequest(cast);
}
}
//makes secondary request to receive URI data in this case "cast"
function sendRequest(cast){
$.ajax({
url: cast + '&sig=' + encryptSig(),
dataType: "json",
success: acceptData
});
}
//accepts URI data
function acceptData(data){
var castResults = data.cast;
for(i in castResults){
$('.cast').append(castResults[i].name);
}
}