Hi Nathan,
I'm not a JSONP expect, but I have a suggestion (below).
On Jul 22, 2009, at 11:27 PM, Nathan Wallman wrote:
> I'm trying to use JQuery to query my ServerResource and then process
> a returned JSONP object. Everything I'm returning appears to be
> correct but when JQuery tries to process it nothing happens. As far
> as I can tell my resource returns everything that other REST
> services do but for some reason mine doesn't work. Here are the
> details about my setup:
>
> Here is the JQuery I'm using:
>
>
http://docs.jquery.com/Ajax/jQuery.getJSON>
> I am running it from the Google AJAX Playground found here:
>
>
http://code.google.com/apis/ajax/playground/#jquery>
> Here is how I'm using JQuery:
>
> google.load("jquery", "1");
>
> // on page load complete, fire off a jQuery json-p query
> // against Google web search
> function OnLoad(){
> var url = "
http://teamwebtools.appspot.com/api/hello?callback=?";
> $.getJSON(url, function () {
> alert("test");
> });
> }
>
> google.setOnLoadCallback(OnLoad);
>
> Here is the URL that is mapped to my ServerResource:
>
>
http://teamwebtools.appspot.com/api/hello>
> Finally here is the code of my ServerResource:
>
> @Get
> public Representation getHelloWorld() throws Exception{
> log.log(Level.WARNING,"Incoming Request");
> StringRepresentation rep = new
> StringRepresentation("({\"responseData\":\"hello, world (from the
> cloud!)\"})", MediaType.APPLICATION_JAVASCRIPT);
> return rep;
> }
The idea with JSONP is that the response from the server is wrapped in
a function call so that when the result is evaluated in the page, the
callback function is automatically invoked with the data. In your
flickr example, e.g., the default callback is "jsonFlickrFeed". You
can change it by providing a different name to the jsoncallback
parameter:
http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=somethingElseYour resource needs to act the same way. As it is, you are only
wrapping the data in parens.
Rhett
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2374903