开发者

Trouble with jQuery getJSON

I am using the following URI like so to pass to jQuery's getJSON.

var publicVidsUrl = 'http://api.publicvideos.org/v/0/clips?callback=?';

$.getJSON(publicVidsUrl, function(data){
    alert(data.length); 
});

...but it is failing. While the JSON returned passes as valid in JSON lint, I am not so sure. The escaped double 开发者_C百科quotes seem fine, but I wonder about the double quotes around each object in the parent array.

Can anyone please help clarify where this error is coming from? Specifically I am getting this error from jQuery in the Firebug Console:

(d || "").split is not a function

I am using jQuery 1.4.2


The API doesn't seem to be meant for javascript consumption, more likely its meant to be handled serverside; PHP, Python, C# etc.

Any javascript you use will fail because of cross domain issues. Unless you happen to be working for publicvideos.org or have access to publish script on their domain.


You have to quote your strings, if you're omitting them in your actual code you'll get a syntax error before anything else happens:

var publicVidsUrl = "http://api.publicvideos.org/v/0/clips?callback=?";


Right so I'm not getting JSONP back from the Public Videos API after all. Hope to get this sorted somehow.


This is not valid JSONP. Valid JSONP should start with a ? and everything should be wrapped in parenthesis. Here's an example of properly formatted JSONP:

?({"posts":[{"id":"6", "url":"sample-6", "title":"sample 6", "content":"sample 6"},{"id":"5", "url":"sample-5", "title":"sample 5", "content":"sample 5"}]});


JSONP is not supported, so a client-side request to this API will not work.

Look all the way at the bottom: http://wiki.publicvideos.org/api/main

Edit: Haha, just noticed that was your own post on the wiki Jerome.. I'll leave this here for posterity's sake :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜