如何使JSONP调用的API使用jquery [英] How to make a jsonp call to an api using jquery

查看:204
本文介绍了如何使JSONP调用的API使用jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的一般编程和我有麻烦获取数据到我的web应用程序,当我做出的moviedb.org API的调用。我使用jQuery和我已阅读所有的文档,甚至菜谱,我仍然在努力使这项工作,我还检查我的谷歌开发者工具控制台,它表明调用成功:

I am new to programming in general and i am having trouble getting the data into my web app when i make a call to the moviedb.org api. I am using jquery and i have read all the docs, even the cookbook and i am still struggling to make this work, i also checked my google dev tools console and it shows that the call was successful:

Status Code:200 OK
[{"id":550,"name":"Fight Club","posters":[{"image":{"type":"poster","size":"original","height":1000,"width":675,"url":"http://hwcdn.themoviedb.org/posters/f8e/4b........

下面是我的code:

<script>
   $.getJSON("http://api.themoviedb.org/2.1/Movie.getImages/en/json/ed7e2e092ca896037ce13d2bf11a08f1/550&callback=?",
    function(data){
      $.each(data, function(i,item){
         $("<img/>").attr("src", item.image).appendTo("#images");
      });
    });
 </script>

我想我搞乱了回调函数,任何想法,将AP preciated。
在此先感谢!

I think i am messing up with the callback function, any thoughts would be appreciated. Thanks in advance!

推荐答案

在短,你打的似乎并不支持JSONP的服务器,这是服务器端的功能,必须是present ...并且不是。我也看到他们的API文档或论坛没有提及。网址应为回调= ,因为它是唯一的查询参数,如:??

In short, the server you're hitting doesn't seem to support JSONP, this is server-side functionality that must be present...and isn't. I also see no mention in their API docs or forums. The URL should be ?callback=? since it's the only querystring parameter, like this:

http://api.themoviedb.org/2.1/Movie.getImages/en/json/<apikey>/550&callback=?

...但是,这仍然无法工作,因为服务器不支持它。正如旁白:很多时候,一些与API密钥的不是的要支持JSONP(因为客户将有钥匙),如果API使用它的关键是限制访问...等使用它只是为了追踪可能不在乎。

...but that still won't work, since the server doesn't support it. Just as an aside: Many times something with an API key isn't going to support JSONP (since the client would have the key), if the API it using the key to restrict access...others using it just for tracking may not care.

这篇关于如何使JSONP调用的API使用jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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