If I have a function like this, i pass in a variable of movieid.
function getFilmDetails(movieid) {
var filmDetails = 0;
$.ajax({
dataType: "json",
type: 'get',
mimeType: "textPlain",
url: 'http://api.themoviedb.org/3/movie/' + movieid,
async: false,
success: function(result){
if(result.popularity > 10000) {
result.popularity = 10000;
}
if(result.popularity < 0.1) {
result.popularity = 0.1;
}
filmDetails = result;
}
});
return filmDetails;
}
I'm calling over 100 films details through this function and as you can imagine, it takes forever to load the page by doing it this way. I need to easily access the values in the JSON for each film. For example:
alert(getFilmDetails(12345).description);
alert(getFilmDetails(65432).popularity);
alert(getFilmDetails(12345).tagline);
Is there a better way to do this?
async:false;... why? Have your function accept a callback.getFilmDetails(12345, function(data) { alert(data); })Then inside your function, inplace of thefilmDetails = result;, invoke the callback, and pass itresult, likecallback(result);