【发布时间】:2014-08-24 04:10:24
【问题描述】:
我正在开发一个个人 jQuery/ajax/json 项目,我正在尝试从 TMDB API 收集数据。我希望人们在哪里搜索某个词,例如电影搏击俱乐部。应该发生的是看到与输入的电影标题匹配的电影海报。
到目前为止我得到了这个:
$.ajax({ 类型:“获取”, 数据类型:“jsonp”, 缓存:假, 网址:“https://api.themoviedb.org/3/search/movie?api_key=257654f35e3dff105574f97fb4b97035&query=fight+club”, 成功:卡通TMDB结果 // 成功时,运行函数 toonTMDBResults });
function toonTMDBresults(tmdbJson) {
console.log('TMDB:', tmdbJson);
if ( 1 == 1 ) { // if 1 equals 1, so always run the following code... :)
for (var idx in tmdbJson.data) { //loop through the results
var results = tmdbJson.data[idx];
console.log(results);
console.log(results.results[0].id); //take the ID of the first result in the array
}
} else {
console.log('problem with the TMDB request:', json.meta.code);
}
我希望在控制台中看到电影的 ID。如果我能够做到这一点,我将能够从 json 数据中选择 poster_path 并在我的 html 中显示电影海报。
但问题是我没有按照我的要求在控制台中获取 ID,所以我做错了。
谢谢,
标记
【问题讨论】:
标签: javascript jquery ajax json api