.getJSON()返回null

时间:2010-06-26 10:39:00

标签: jquery json getjson

我正在使用jQuery来使用示例flickr服务来获取和解析JSON:http://api.jquery.com/jQuery.getJSON/

如果我使用flickr网址,一切正常,当我尝试获得自己的服务时问题就开始了。

当我保存输出并从文件中读取它但我无法从服务器URL工作时它工作。 Firebug显示两个对象为null,这很明显,但它也显示如下:

GET http://myurl.xx 200 OK 107ms


Date Sat, 26 Jun 2010 10:24:08 GMT
Server Apache/2
X-Powered-By PHP/5.2.10
Set-Cookie SESS1faf247ad9843d9dd296b3673ae414f3=1e90f24286485ce326718211ed258733; expires=Mon, 19-Jul-2010 13:57:28 GMT; path=/; domain=.myrul.xx
Expires Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified Sat, 26 Jun 2010 10:24:08 GMT
Cache-Control store, no-cache, must-revalidate, post-check=0, pre-check=0
Vary Accept-Encoding,User-Agent
Content-Encoding gzip
Content-Length 1167
Keep-Alive timeout=1, max=100
Connection Keep-Alive
Content-Type text/javascript; charset=utf-8


Request headers


Host myurl.xx
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; pl; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 ( .NET CLR 3.5.30729; .NET4.0E)
Accept application/json, text/javascript, */*
Accept-Language pl,en-us;q=0.7,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-2,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Origin null

我已将网址更改为:myrul.xx但我使用了有效的网址。

结果可能是什么原因?

例如我尝试过(我不使用任何查询字符串):

 $.getJSON('http://mysite.com', function (jd) {
   $.each(jd, function (index, value) {
       $('#stage').append('<p>' + value.title + '</p>');
       $('#stage').append('<img src=\'' + value.picture + '\'></p>');
       $('#stage').append('<p><a href=\'' + value.url + '\'>url</a></p>');
       $('#stage').append('<hr/>');
   });
});

1 个答案:

答案 0 :(得分:0)

您需要在网址中添加回调 即Flickr有jsoncallback

  

http://api.flickr.com/services/feeds/photos_public.gne?tagmode=any&format=json&jsoncallback=

相关问题