开发者

Unable to Read Data from Jquery getJSON Request

I'm requesting a json feed using the standard jquery getJson request. The json url is not hosted on my domain.

$.getJSON('myfeed.json?jsoncallback=?',

function(data){
 console.log(data);
})

However using Firebug, I'm not seeing any data logged in the console. But I can see the json data has been loa开发者_如何学Pythonded as is available when I look under the Net panel in Firebug.

Anyone know why this is?

Sample JSON

[{
    "person": {
        "name": "Bob",
    }
},
{
    "person": {
        "name": "Dave",
    }
},
{
    "person": {
        "name": "Jim",
    }
}
}]


Make sure that:

  1. The console is on at all. Type javascript:console.log('test') into the address bar to see if anything comes up - sometimes you need to refresh the page in order to get the console running properly.
  2. The feed on the other domain is, in fact, built for JSON-P, which is required when accessing feeds on other domains. What feed are you actually trying to access?


I think the getJSON method doesn't parse the content unless you're content-type header is text/json. You can either change your server side header or perhaps do something like this

$.get("http://MYURL", function(data){
  var jsondata = eval("("+data+")")
}


Make sure that the json data is well formed and also that the server returns an appropriate content type. Place a breakpoint at the console.log. Most probably this isn't executed as the callback doesn't run for some reason.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜