I've got an AIR app I'm working on, one in which I'll be needing to
make a few calls from the user's desktop to our login server. I found
on the jQuery site where it says that cross domain calls work fine if
you return JSON data using the JSONP format. The demo works just fine,
but when I try to replicate it using my code, I get no data, or an
error. Can anyone tell me what I'm missing? Here's the two samples,
the one copied straight from the docs, the other copied and pasted
from my code:
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne? tags=cat&tagmode=any&format=json&jsoncallback=?",
function(data){
alert(data);
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo("#content");
if ( i == 3 ) return false;
}
);
For the above code sample, it correctly throws an alert, then outputs
images of cats into the specified container.
For my code it does nothing. No errors, but also no alert. It's almost
like it's not returning anything to the page, but in Firebug I see
that the call is being made. In fact, here's the URL that Firebug
shows is going out:
Try going to the commadelimited.com URL directly in your browser. It
looks like it's not returning the correct JSONP format.
Flickr returns (with callback=foo in the URL):
foo( {...json...} )
and commadelimited returns:
[ {...json...} ]
So it looks like the problem is on the server side.
Remember, jQuery uses JSONP by creating a <script> element and using
the URL as the src attribute, so the returned text is executed as
javascript.
foo( {...json...} );
calls the function foo with the relevant data so you can use it.
[ {...json...} ];
creates an array with the data but promptly throws it away.
Danny
On Mar 13, 6:51 am, Andy Matthews <andyandja...@gmail.com> wrote:
> For the above code sample, it correctly throws an alert, then outputs
> images of cats into the specified container.
> For my code it does nothing. No errors, but also no alert. It's almost
> like it's not returning anything to the page, but in Firebug I see
> that the call is being made. In fact, here's the URL that Firebug
> shows is going out:
-----Original Message----- From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On
Behalf Of Danny Sent: Thursday, March 13, 2008 7:55 AM To: jQuery (English) Subject: [jQuery] Re: $getJSON problem...demo works, but not my code?
Try going to the commadelimited.com URL directly in your browser. It looks like it's not returning the correct JSONP format. Flickr returns (with callback=foo in the URL): foo( {...json...} ) and commadelimited returns: [ {...json...} ]
So it looks like the problem is on the server side.
Remember, jQuery uses JSONP by creating a <script> element and using the URL as the src attribute, so the returned text is executed as javascript. foo( {...json...} ); calls the function foo with the relevant data so you can use it. [ {...json...} ]; creates an array with the data but promptly throws it away.
Danny
On Mar 13, 6:51 am, Andy Matthews <andyandja...@gmail.com> wrote: > For the above code sample, it correctly throws an alert, then outputs > images of cats into the specified container.
> For my code it does nothing. No errors, but also no alert. It's almost > like it's not returning anything to the page, but in Firebug I see > that the call is being made. In fact, here's the URL that Firebug > shows is going out:
> Try going to the commadelimited.com URL directly in your browser. It
> looks like it's not returning the correct JSONP format.
> Flickr returns (with callback=foo in the URL):
> foo( {...json...} )
> and commadelimited returns:
> [ {...json...} ]
> So it looks like the problem is on the server side.
> Remember, jQuery uses JSONP by creating a <script> element and using
> the URL as the src attribute, so the returned text is executed as
> javascript.
> foo( {...json...} );
> calls the function foo with the relevant data so you can use it.
> [ {...json...} ];
> creates an array with the data but promptly throws it away.
> Danny
> On Mar 13, 6:51 am, Andy Matthews <andyandja...@gmail.com> wrote:
> > For the above code sample, it correctly throws an alert, then outputs
> > images of cats into the specified container.
> > For my code it does nothing. No errors, but also no alert. It's almost
> > like it's not returning anything to the page, but in Firebug I see
> > that the call is being made. In fact, here's the URL that Firebug
> > shows is going out:
jQuery replaces the '?' in the URL with a function name. Try the URL's
with something like 'callback=foo' in there; you'll notice that Flickr
puts that name in the return as a function call (' foo( {..})') while
your's still returns just [ {..} ]. And yes, using square brackets
instead of parentheses will give an error if you use them in a
function call
On Mar 13, 9:33 am, "Andy Matthews" <li...@commadelimited.com> wrote:
> But when I view both URLs directly in the browser there appears to be no
> difference in the return.
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On
> Behalf Of Danny
> Sent: Thursday, March 13, 2008 7:55 AM
> To: jQuery (English)
> Subject: [jQuery] Re: $getJSON problem...demo works, but not my code?
> Try going to the commadelimited.com URL directly in your browser. It looks
> like it's not returning the correct JSONP format.
> Flickr returns (with callback=foo in the URL):
> foo( {...json...} )
> and commadelimited returns:
> [ {...json...} ]
> So it looks like the problem is on the server side.
> Remember, jQuery uses JSONP by creating a <script> element and using the URL
> as the src attribute, so the returned text is executed as javascript.
> foo( {...json...} );
> calls the function foo with the relevant data so you can use it.
> [ {...json...} ];
> creates an array with the data but promptly throws it away.
> Danny
> On Mar 13, 6:51 am, Andy Matthews <andyandja...@gmail.com> wrote:
> > For the above code sample, it correctly throws an alert, then outputs
> > images of cats into the specified container.
> > For my code it does nothing. No errors, but also no alert. It's almost
> > like it's not returning anything to the page, but in Firebug I see
> > that the call is being made. In fact, here's the URL that Firebug
> > shows is going out:
I talked it over with a co-worker and it appears that this is more an issue with ColdFusion's version of JSON. I don't think that ColdFusion understands JSONp at the moment.
-----Original Message----- From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On
Behalf Of Danny Sent: Thursday, March 13, 2008 1:29 PM To: jQuery (English) Subject: [jQuery] Re: $getJSON problem...demo works, but not my code?
jQuery replaces the '?' in the URL with a function name. Try the URL's with something like 'callback=foo' in there; you'll notice that Flickr puts that name in the return as a function call (' foo( {..})') while your's still returns just [ {..} ]. And yes, using square brackets instead of parentheses will give an error if you use them in a function call
On Mar 13, 9:33 am, "Andy Matthews" <li...@commadelimited.com> wrote: > Danny...
> But when I view both URLs directly in the browser there appears to be > no difference in the return.
> -----Original Message----- > From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] > On
> Behalf Of Danny > Sent: Thursday, March 13, 2008 7:55 AM > To: jQuery (English) > Subject: [jQuery] Re: $getJSON problem...demo works, but not my code?
> Try going to the commadelimited.com URL directly in your browser. It > looks like it's not returning the correct JSONP format. > Flickr returns (with callback=foo in the URL): > foo( {...json...} ) > and commadelimited returns: > [ {...json...} ]
> So it looks like the problem is on the server side.
> Remember, jQuery uses JSONP by creating a <script> element and using > the URL as the src attribute, so the returned text is executed as javascript. > foo( {...json...} ); > calls the function foo with the relevant data so you can use it. > [ {...json...} ]; > creates an array with the data but promptly throws it away.
> Danny
> On Mar 13, 6:51 am, Andy Matthews <andyandja...@gmail.com> wrote: > > For the above code sample, it correctly throws an alert, then > > outputs images of cats into the specified container.
> > For my code it does nothing. No errors, but also no alert. It's > > almost like it's not returning anything to the page, but in Firebug > > I see that the call is being made. In fact, here's the URL that > > Firebug shows is going out: