目前我被卡住了我想使用themoviedb api返回标题,情节和海报我不知道如何开始编码
目前,当我运行搜索时,信息显示在浏览器的控制台日志中我想要获取该信息并将其设置为表格格式没有任何花哨只是标题和海报需要帮助没有线索从哪里开始
doc site here http://docs.themoviedb.apiary.io/#get-%2F3%2Fsearch%2Fmovie
<html>
<head>
<title>Sample Seach</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var url = 'http://api.themoviedb.org/3/',
mode = 'search/movie',
input,
movieName,
key = '?api_key=My API KEY HERE';
$('button').click(function() {
var input = $('#movie').val(),
movieName = encodeURI(input);
$.ajax({
url: url + mode + key + '&query='+movieName ,
dataType: 'jsonp',
success: function(data) {
console.log(data);
}
});
});
});
</script>
</head>
<body>
<input id="movie" type="text" /><button>Search</button>
</body>
</html>
答案 0 :(得分:2)
基本上,你试图做得太快。用$(document).ready(...)
包裹你的功能。
$(document).ready(function() {
var url = 'http://api.themoviedb.org/3/',
mode = 'search/movie',
input,
movieName,
key = '?api_key=api key here';
$('button').click(function() {
var input = $('#movie').val(),
movieName = encodeURI(input);
$.ajax({
url: url + mode + key + '&query='+movieName ,
dataType: 'jsonp',
success: function(data) {
console.log(data);
},
error: function (request, status, error) {
alert(status + ", " + error);
}
});
});
});
<input id="movie" type="text" /><button>Search</button>