【发布时间】: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