[jQuery] Re: getJSON data problem for getting youtube json data

2008-03-07 Thread Joe Maller

There are a problems requesting JSON object from GDATA using jQuery.
jQuery appends a timestamp to the url which causes GData to throw an
"Invalid parameter" error. If you check with FireBug, you'll see it.

Also, GData's API says to use "alt=json-in-script" instead of just
"alt=json". It's hard to find, and I made the same mistake at first.
Without a callback parameter in the query, GData will return the
object wrapped in "gdata.io.handleScriptLoaded({...})" but jQuery
seems to want to try callback-less JSON requests as XHRs.

I ended up working around these problems by manually inserting the
script and building a dummy gdata.id object to catch the result. It's
clumsy but it works and will be easy to convert once jQuery and GData
start to get along better.


gdataURL =
http://gdata.youtube.com/feeds/api/videos?format=1&vq=cat&start-index=10&max-results=20&orderby=viewCount&alt=json-in-script


// insert the script:
var s = document.createElement('script');
s.src = gdataURL;
document.getElementsByTagName('head')[0].appendChild(s);


//fake object:
gdata = { io: { handleScriptLoaded: function(data)
{ JSONparser(data); } } };



I've posted to this list about this and opened an issue with Google:
http://code.google.com/p/gdata-issues/issues/detail?id=390

Hope this helps,

joe



On Mar 7, 3:36 am, Saidur <[EMAIL PROTECTED]> wrote:
> Hi ,
> I want to get the json data from the youtube api (http://
> code.google.com/apis/youtube/developers_guide_protocol.html).
>
> My code is like :
>  url="http://gdata.youtube.com/feeds/api/videos?format=1&vq=cat&start-
> index=10&max-results=20&orderby=viewCount&alt=json";
>
> $.getJSON(url,callBackFucntion);
>
> function callBackFucntion ()
> {
>   // here parse the json data
>
> }
>
> But i got an error when i run this code.
> [Exception... "'Permission denied to call method XMLHttpRequest.open'
> when calling method: [nsIDOMEventListener::handleEvent]" nsresult:
> "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: ""
> data: no]
>
> so agian i change the url and add the callback parameter with ?  :
>   url="http://gdata.youtube.com/feeds/api/videos?format=1&vq=cat&start-
> index=10&max-results=20&orderby=viewCount&alt=json&callback=?";
>      $.getJSON(url,fucntion (data){ // parse json data
>                alert ('json data get');
>
> });
>
> This time i do not get error . But i do not get the call back
>
> So how can i get the json data problem
>
> Thanks
> Saidur Rahman


[jQuery] Re: $.getJSON doesn't work on Vista PC while calling remote server

2008-03-07 Thread Joe Maller

I've had issues where jQuery's JSON requests were treated as XHRs if
there was no JSONp callback. That obviously doesn't work going cross-
domain.

If you change your url to /http://stufftolet.com/test/usercontacts.js?
callback=?" it should work, though you're going to need to hook up the
result.

joe

On Mar 7, 9:55 am, Plant More Tree <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
>     if tried the following where usercontacts.j is in my localhost pc
> windows vista (tomcat6) and alert showed like [object object] mean there's
> some object in json argument:
>
>     $.getJSON("usercontacts.js", function(json){
>       alert(json);
>     });
>
> so when I changed to remote location :
>
>     $.getJSON("http://stufftolet.com/test/usercontacts.js";, function(json){
>       alert(json);
>     });
>
> the alert doesn't work alert anymore. However, both behavior (local and
> remote) works on windows xp in my office. Is it some kind of security issue
> where stupid vista try to block outgoing connection? Appreciate any advice
> and help, Thanks !
>
> regards,
> Mark
>
> --
> View this message in 
> context:http://www.nabble.com/%24.getJSON-doesn%27t-work-on-Vista-PC-while-ca...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.


[jQuery] GData JSON queries "Invalid query parameters:_"

2008-03-07 Thread Joe Maller

I've been running into a problem querying GData (Google's Data APIs)
using jQuery and JSON. jQuery's ajax function automatically adds a
cache-buster timestamp to the query, and Google is barfing on it.

The timestamp is inserted starting around line 2608 in jQuery 1.2.3.

As an example, here is an example JSON query url as sent by jQuery:

http://gdata.youtube.com/feeds/videos/ysTmUTQ5wZE?alt=json-in-script&callback=jsonp1204907988594&_=1204907988789

That returns "Invalid query parameters:_"

Removing the underscore timestamp parameter and Google returns the
JSON object:

http://gdata.youtube.com/feeds/videos/ysTmUTQ5wZE?alt=json-in-script&callback=jsonp1204907988594


In the end, I ended up inserting the JSON loading script tags into the
page the old-fashioned way, missing out on all benefits of using
jQuery for this.

I'm also filing a bug with Google encouraging them to fail a touch
more gracefully when faced with unknown query parameters. Please star
issue 390 to help get their attention:

http://code.google.com/p/gdata-issues/issues/detail?id=390


[jQuery] Extract a script from script.src with a script

2008-01-06 Thread Joe Maller

This is a bit of an odd request, but maybe there's something simple
I'm overlooking.

I have a function which pulls JSON data from Google's GData service.
Normally this works pretty well, save a bug or two on Google's end.
The problem is that errors are served as a plain text string without a
JSON wrapper. This throws a parse error in the browsers. What I want
to do is read that string.

Is there a way to extract/view/read the script contents of an external
script with a script?

I want to use JQuery or raw JavaScript to read the returned value. The
string is visible in the web inspectors in Safari and Firefox, but
nothing I've come up with has managed to reveal it.

The only real catch here is that the solution must be 100% client-
side, there can be no server-side proxy.