1

目前我被卡住了我想使用 themoviedb api 返回标题、情节和海报我不知道如何开始为此编码

目前,当我运行搜索时,信息显示在浏览器的控制台日志中

文档网站在这里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>
4

1 回答 1

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>
于 2014-04-01T11:55:53.420 回答