jerome
jerome

Reputation: 4977

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

Upvotes: 1

Views: 657

Answers (5)

Sandro
Sandro

Reputation: 4771

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

Upvotes: 0

Brian Ray
Brian Ray

Reputation: 1492

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"}]});

Upvotes: 0

jerome
jerome

Reputation: 4977

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

Upvotes: 0

Kristoffer Sall-Storgaard
Kristoffer Sall-Storgaard

Reputation: 10636

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.

Upvotes: 1

user229044
user229044

Reputation: 239250

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=?";

Upvotes: 0

Related Questions