【问题标题】:extracting json data using jquery使用jquery提取json数据
【发布时间】:2015-07-28 05:07:58
【问题描述】:

使用 tmdb api 使用 jquery 提取电影信息

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

点击按钮会调用api,

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

//giving errors in get 

 $.getJSON(newurl+"?callback=?",function(json){

    console.log(json[0].results[0].original_title); 
//printing the movie title on the ***console*** 

 });
    });
});

它给了我以下错误

GET http://api.themoviedb.org/3/search/movie?query=avengers&api_key=fed63cb1875…9a2aed7e?callback=jQuery19104732654287945479_1438057058565&_=1438057058566

b.extend.ajax b.extend.getJSON (匿名函数) b.event.dispatch v.句柄

加载资源失败:服务器响应状态为 401(未授权)

【问题讨论】:

标签: javascript jquery ajax json


【解决方案1】:

您必须提供 valid key

Invalid Key:

http://api.themoviedb.org/3/search/movie?query=avengers&api_key=fed63cb1875

请按如下方式使用api_key

fed63cb1875f494391fd712f9a2aed7e

请查看以下url:

http://api.themoviedb.org/3/search/movie?query=avengers&api_key=fed63cb1875f494391fd712f9a2aed7e

【讨论】:

    猜你喜欢
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多