$(document).on('pageinit', '#home', function(){
// $(document).ready(function(){
console.info('hi');
var latestUrl = 'https://api.themoviedb.org/3/movie/latest?',
singleUrl = 'https://api.themoviedb.org/3/movie/'
mode = 'search/movie?query=',
key = '&api_key=7b0b1d8b1253e2bbfcd5602f76c52fdb',
latestId = 0,
targetId = 0;
$.ajax({
url: latestUrl + key ,
dataType: "jsonp",
async: true,
success: function (result) {
console.dir(result);
// ajax.parseJSONP(result);
latestId = result.id;
console.info(latestId);
targetId = Math.floor(Math.random() * latestId);
console.info(targetId);
callFilmId(targetId);
},
error: function (request,error) {
alert('Network error has occurred please try again!');
}
});
// get random id
});
function callFilmId(tid){
$.ajax({
url: "https://api.themoviedb.org/3/movie/"+tid+"?api_key=7b0b1d8b1253e2bbfcd5602f76c52fdb&language=en-US",
dataType: "jsonp",
async: true,
success: function (result) {
console.dir(result);
if(result.status_code == 34){
callFilmId(tid+1);
}
// ajax.parseJSONP(result);
},
error: function (request,error) {
// alert('Network error has occurred please try again!');
callFilmId(tid+1);
}
});
}
$(document).on('pagebeforeshow', '#headline', function(){
$('#movie-data').empty();
$.each(movieInfo.result, function(i, row) {
if(row.id == movieInfo.id) {
$('#movie-data').append('<li><img src="http://image.tmdb.org/t/p/w92'+row.poster_path+'"></li>');
$('#movie-data').append('<li>Title: '+row.original_title+'</li>');
$('#movie-data').append('<li>Overview <br>'+row.overview+'</li></br>');
$('#movie-data').append('<li>Popularity : '+row.vote_average+'</li>');
$('#movie-data').listview('refresh');
$('#movie-data').append('<li>Release Date'+row.primary_release_year+'</li>');
}
});
});
$(document).on('vclick', '#movie-list li a', function(){
movieInfo.id = $(this).attr('data-id');
$.mobile.changePage( "#headline", { transition: "slide", changeHash: false });
});
var movieInfo = {
id : null,
result : null
}
var ajax = {
parseJSONP:function(result){
movieInfo.result = result.results;
$.each(result.results, function(i, row) {
console.log(JSON.stringify(row));
$('#movie-list').append('<li><a href="" data-id="' + row.id + '"><img src="http://image.tmdb.org/t/p/w92'+row.poster_path+'"/><h3>' + row.title + '</h3><p>')
})
}
}
برچسب:
نویسنده: آیلین رضوانی