Skip to content

Instantly share code, notes, and snippets.

@fanqi
Last active April 24, 2017 02:57
Show Gist options
  • Save fanqi/2e33b06b729bd7b5de9902413326f64c to your computer and use it in GitHub Desktop.
Save fanqi/2e33b06b729bd7b5de9902413326f64c to your computer and use it in GitHub Desktop.
call rest api to show movie info
<p>昆明正在上映的电影: <select id="movie"><option value="">请选择。。。</option> </select></p>
<hr />
<p id="intro">&nbsp;</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>平均评分 : &nbsp; </b>' + data.rating.average + '<br/>';
intro += '<b>评分人数 : &nbsp; </b>' + data.ratings_count + '<br/>';
intro += '<b>看过人数 : &nbsp; </b>' + data.reviews_count + '<br/>';
intro += '<b>剧情简介 : &nbsp; </b>' + data.summary + '<br/>';
Y.one('#intro').setHTML(intro);
}
}
}
);
}
}
);
});
</script>
<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">&nbsp;</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>平均评分 : &nbsp; </b>'+data.rating.average+'<br/>';
intro+='<b>评分人数 : &nbsp; </b>'+data.ratings_count+'<br/>';
intro+='<b>看过人数 : &nbsp; </b>'+data.reviews_count+'<br/>';
intro+='<b>剧情简介 : &nbsp; </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