I didn't know that GAE / Django supported callbacks, but they're really not
needed, since you supply your own handler function in Dojo ('load').
If the json object is properly formatted, it will be returned as text and
evaluated by Dojo (since you're using handleAs:'json').

So add a load function, and ditch the extraneous callbacks parameter;

 dojo.io.script.get({
>                         url: "http://localhost:8080/rpc?";,
>                         content: {
>                             action: "Add",
>                             arg0: "1",
>                             arg2: "2",
>                            time: Date()
>                         },
>                         handleAs: "json",
>                         preventCache: true,
>                         error: function(text){
>                             alert("An error has occurred - " + text);
>                             return text;
>                         },
>                         load: function(response)
                           {
                               // The response variable will now be a normal
js object referring to the evaluated json
                           }
>                     });
>                 }


Also, I changed 'text/json' to only 'json'. For security reasons you should
use jsonp, which assumes that all json is wrapped in a comment '/* ... */',
but you have to be sure the server does that as well :)

A final note; You might not need to use dojo.io.script, which is only
required if you're loading cross-domain. If you're conecting back to the
same domain the page was loaded from, you can use dojo.xhrGet instead, which
is slightly quicker.

.. I would also recommend that you use firebug (or the Dojo firebug lite
console for mentally challenged browsers, which pops up if you use
isDebug:true in djConfig, so you don't have to suffer alerts :)

Cheers,
PS



On Tue, Sep 9, 2008 at 8:49 AM, Bill <[EMAIL PROTECTED]> wrote:

>
> I've been building some AJAX clients that call App Engine backends.
> I'm not sure what documentation your citing, but App Engine is just
> like any server out there.  The standard webapp framework nicely
> handles GET, POST, and other HTTP actions/verbs.  You can set the
> content header in your handler by doing this:
>
> self.response.headers['Content-Type'] = 'text/javascript'   # or
> 'application/json' if you think IE won't choke on it
> self.response.out.write(...some json...)
>
> That's it.  The hard part on the backend is the code that autoconverts
> datastore structures into json.  In particular, you have to convert
> datetime and recurse down into lists and dictionaries and convert them
> to simple json types.
>
> On Sep 8, 8:42 pm, Downtown <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I am attempting to write a GAE application using AJAX.  It states:
> >
> > "In its most generic sense, an AJAX Request will have a function name
> > followed by any optional parameters, the last of which, if it is a
> > function, is an optional OnSuccess callback. So, lets write a function
> > that handles this:
> >
> > .........
> > (resulting in ......)
> >
> >
> GEThttp://localhost:8080/rpc?action=Add&arg0=%221%22&arg1=%222%22&time=1...
> > ...."
> >
> > Where is the "OnSuccess" callback??  It is missing from the GET URL.
> > Can I assume the following is correct:
> >
> >
> GEThttp://localhost:8080/rpc?action=Add&arg0=%221%22&arg1=%222%22&time=1...
> >
> > Also, can I assume on the server side:
> >
> > self.response.out.write(simplejson.dumps(result)).......will send the
> > response to myjavascriptfunction??
> >
> > If I am missing something fundamental, please explain.  If not, please
> > update the example to include better documentation on the callback
> > function.
> >
> > P.S.  If you help me fine tune your example I will post a Dojo
> > equivalent that would substantially reduce coding the AJAX GET.  In
> > Dojo it would be as simple as:
> >
> >  dojo.io.script.get({
> >                         url: "http://localhost:8080/rpc?";,
> >                         content: {
> >                             action: "Add",
> >                             arg0: "1",
> >                             arg2: "2",
> >                            time: Date(),
> >                            OnSuccess: "myjavascriptfunction"
> >                         },
> >                         handleAs: "text/json",
> >                         preventCache: true,
> >                         error: function(text){
> >                             alert("An error has occurred - " + text);
> >                             return text;
> >                         }
> >                     });
> >                 }
> >
> > Thanks!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to