views:

82

answers:

5

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 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

A: 

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=?";
meagar
There are quotes around the string, single quotes.
jerome
There weren't at the time I posted the answer, and I'm unable to delete it for some reason; clicking delete cast a vote to delete it rather than deleting it outright.
meagar
+1  A: 

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.

Kristoffer S Hansen
If you run the code you will see that the getJSON function does return JSONP, I don't think this is a crossdomain issue.
jerome
No, it returns JSON, there is a difference http://en.wikipedia.org/wiki/JSON#JSONP
Kristoffer S Hansen
A: 

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

jerome
A: 

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"}]});
Brian Ray
A: 

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 :)

Sandro