Last active
April 24, 2017 02:57
-
-
Save fanqi/2e33b06b729bd7b5de9902413326f64c to your computer and use it in GitHub Desktop.
call rest api to show movie info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>昆明正在上映的电影: <select id="movie"><option value="">请选择。。。</option> </select></p> | |
<hr /> | |
<p id="intro"> </p> | |
<script> | |
YUI().use('aui-io-request','node',function(Y){ | |
Y.io.request( | |
'https://api.douban.com/v2/movie/in_theaters?city=%E6%98%86%E6%98%8E', | |
{ | |
dataType: 'json', | |
method: 'GET', | |
on: { | |
success: function() { | |
var data = this.get('responseData'); | |
var movieOptions = ''; | |
for (var i = 0; i < data.count; i++) { | |
movieOptions += '<option value="' + data.subjects[i].id + '">' + data.subjects[i].title + '</option>'; | |
} | |
Y.one('#movie').append(movieOptions); | |
} | |
} | |
} | |
); | |
Y.one('#movie').on( | |
'change', | |
function() { | |
var id = this.get('value'); | |
if (id !== '') { | |
Y.io.request( | |
'http://api.douban.com/v2/movie/subject/' + id, | |
{ | |
dataType: 'json', | |
on: { | |
success: function() { | |
var data = this.get('responseData'); | |
var intro = ''; | |
intro += '<img src="' + data.images.large + '"><br/>'; | |
intro += '<b>平均评分 : </b>' + data.rating.average + '<br/>'; | |
intro += '<b>评分人数 : </b>' + data.ratings_count + '<br/>'; | |
intro += '<b>看过人数 : </b>' + data.reviews_count + '<br/>'; | |
intro += '<b>剧情简介 : </b>' + data.summary + '<br/>'; | |
Y.one('#intro').setHTML(intro); | |
} | |
} | |
} | |
); | |
} | |
} | |
); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script> | |
<p>昆明正在上映的电影: <select id="movie"><option value="">请选择。。。</option> </select></p> | |
<hr /> | |
<p id="intro"> </p> | |
<script> | |
$.ajax({ | |
method: 'get', | |
url: 'https://api.douban.com/v2/movie/in_theaters?city=%E6%98%86%E6%98%8E', | |
type: 'json', | |
}).done(function( data ) { | |
var movieOptions = ''; | |
for (var i = 0; i < data.count; i++) { | |
movieOptions+='<option value="'+data.subjects[i].id+'">'+data.subjects[i].title+'</option>'; | |
} | |
$('#movie').append(movieOptions); | |
}); | |
$('#movie').on('change',function(){ | |
var id = $('#movie').val(); | |
var url = 'http://api.douban.com/v2/movie/subject/'+id; | |
$.ajax({ | |
method: "get", | |
url: url, | |
type: 'json', | |
}).done(function( data ) { | |
var intro =''; | |
intro+='<img src="'+data.images.large+'"><br/>'; | |
intro+='<b>平均评分 : </b>'+data.rating.average+'<br/>'; | |
intro+='<b>评分人数 : </b>'+data.ratings_count+'<br/>'; | |
intro+='<b>看过人数 : </b>'+data.reviews_count+'<br/>'; | |
intro+='<b>剧情简介 : </b>'+data.summary+'<br/>'; | |
$('#intro').html(intro); | |
}); | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment