themoviedb JSON API与jQuery [英] themoviedb JSON API with jQuery

查看:645
本文介绍了themoviedb JSON API与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些事情,似乎应该是简单的。得到的文本字段的输入和通过API搜索它的themoviedb.org数据库

I'm trying to do something that seems like it should be simple. Get the input of a text field and search the themoviedb.org database for it via the API.

我使用jQuery和themoviedb.org APIv3,支持JSONP。我得到的,虽然是这样回应:

I'm using jQuery and the themoviedb.org APIv3, which supports JSONP. All I get, though, is this response:

{状态_ code:6,STATUS_MESSAGE:无效的ID - 的pre-必要的id是无效或找不到}

这并没有真正告诉我很多。什么ID?

That doesn't really tell me a lot. ID of what?

事情我知道了:


  • 我有正确的API密钥

  • 搜索按钮提交和正确地获取输入的值

下面是一个的jsfiddle 和这里的的 API文档了解搜索电影。此外,检查出 API文档的这个版本。我认为它与查询参数来做。

Here's a jsfiddle, and here's the API documentation about searching movies. Also, check out this version of the API docs. I think it has to do with the query params.

说真的,我不知道我和JSON做的,所以我希望这将是一个重新presentative例子,这将有助于我理解这一点。

Really, I have no idea what I'm doing with JSON, so I'm hoping this will be a representative example that will help me understand it.

推荐答案

您只需要查询字符串参数的正确数目。所需PARAMATERS是查询 API_KEY 。我在这里找到这些要求<一个href=\"http://docs.themoviedb.apiary.io/#get-%2F3%2Fsearch%2Fmovie\">http://docs.themoviedb.apiary.io/#get-%2F3%2Fsearch%2Fmovie.试试这个来代替:

You just need the correct number of query string parameters. The required paramaters are query and api_key. I found these requirements here http://docs.themoviedb.apiary.io/#get-%2F3%2Fsearch%2Fmovie. Give this a try instead:

$(document).ready(function() {
    var url = 'http://api.themoviedb.org/3/',
        mode = 'search/movie?query=',
        input,
        movieName,
        key = '&api_key=470fd2ec8853e25d2f8d86f685d2270e';

    $('button').click(function() {
        var input = $('#movie').val(),
            movieName = encodeURI(input);
        $.ajax({
            type: 'GET',
            url: url + mode + input + key,
            async: false,
            jsonpCallback: 'testing',
            contentType: 'application/json',
            dataType: 'jsonp',
            success: function(json) {
                console.dir(json);
            },
            error: function(e) {
                console.log(e.message);
            }
        });
    });
});​

工作小提琴: http://jsfiddle.net/fewds/srdHD/3/

注意: 因为这就是最有可能您的 API密钥我会建议申请一个新的

Note: Since thats most likely your REAL api key I would suggest requesting a new one!

这篇关于themoviedb JSON API与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆