$ .getJSON语法问题 [英] $.getJSON syntax issue

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

问题描述

我快要撕裂了我的眼睛来吃了。我想拉来自Flickr的数据,显然我不知道我在做什么。

I'm about to rip out my eyes and eat them. I'm trying to pull data from flickr and apparently I have no idea what I'm doing.

本作品:

var flickrAPI = "https://api.flickr.com/services/rest/api_key=xxxxx";
$.get(flickrAPI, 
{
method: "flickr.photosets.getList",
format: "json",
user_id: "xxxxx"
}, alert("ok")
);

和我惊动OK 然而,当我尝试使用功能(){}到位警报()......

And I am alerted "ok" However when I try to use function() {} in place of alert()...

var flickrAPI = "https://api.flickr.com/services/rest/api_key=xxxxx";
$.get(flickrAPI, 
{
method: "flickr.photosets.getList",
format: "json",
user_id: "xxxxx"
}, function(data) {alert("ok");}
);

什么也没有发生。

Nothing happens.

另外,如果我的$不用彷徨的返回值赋给一个变量,我留下了以下JSON对象:

Also, if I assign the return value of $.get to a variable, I'm left with the following JSON object:

{"readyState" : "1"}

这是不是我要找的。有任何想法吗?这可能是值得一提的是,HTML文件,我正与一个本地文件。

which is not what I'm looking for. any ideas? It might be worth noting that the html file I'm working with is a local file.

感谢

推荐答案

您不能检索使用AJAX从另一台主机的数据,因为=htt​​ps://developer.mozilla.org/en-US/docs/网络/ JavaScript的/ Same_origin_policy_for_JavaScript相对=nofollow>同源策略。

You cannot retrieve data from another host using AJAX because of the same-origin policy.

它可能会使用 JSONP ,如果其他主机支持它。它解释了如何使用 JSONP 使用jQuery在 jQuery的手动。在Flickr的具体情况下,有一个博文解释如何使用JSONP与Flickr。

It may be possible to use jsonp if the other host supports it. It is explained how to use jsonp with jQuery in the jQuery manual. In the specific case of Flickr there is a blogpost explaining how to use jsonp with flickr.

这篇关于$ .getJSON语法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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