我有以下javascript代码,问题是首先执行了函数getBestMovies4BestPCRating();
并且在amovies.forEach(function(item) {
之后
任何想法?
document.getElementById('sendMovies').addEventListener('click', function() {
var movieIDs = document.getElementById('MovieIDs').value;
var data = {};
var amovies = {};
var movies = {};
data["movieList"] = '[' + movieIDs + ']';
params = JSON.stringify(data);
var http = new XMLHttpRequest();
var url = "http://............."
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/json");
http.onreadystatechange = function() { //Call a function when the state changes.
if (http.readyState == 4 && http.status == 200) {
movies = http.responseText;
amovies = JSON.parse(movies);
amovies.forEach(function(item) {
if (item.rating > 4) {
getEntitiesRatings(item.ratingsPK.userId, 0);
}
});
getBestMovies4BestPCRating();
convertmovies2table(bestMovies);
}
}
http.send(params);
});
function getEntitiesRatings(userid, kind) {
var xmlhttp = new XMLHttpRequest();
var url = " http://.............entities.ratings/" + userid;
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
if (kind == 0) {
computeUserColleration(myArr, userid);
}
if (kind == 1) {
bestUserMovies(myArr, userid);
}
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
答案 0 :(得分:1)