Couple of quick points here:
1) In your example (Downtown), you don't need to use eval. When you
specify "handleAs: 'json'" the response is already JSON (already
evaled underneath). You don't need to worry about YUI and all,
although the commented format suggested above is ideal.
2) In response to Peter above, GAE only "supports callbacks" in the
same sense that any server supports callbacks. You have to manually
include the callback function in your response, as in "callbackFunc("
+ json + ")"
-Adam
On Sep 12, 11:23 am, Bill <[EMAIL PROTECTED]> wrote:
> You might want to use Crockford's JSON utility instead of the naked
> eval of the response. See the section "A word of caution against using
> eval" on the YUI JSON page:http://developer.yahoo.com/yui/json/
>
> The original non-YUI version can be used as well:http://json.org/json2.js
>
> On Sep 12, 6:36 am, Downtown <[EMAIL PROTECTED]> wrote:
>
> > Thanks for all the posts. I have GET working very well. I had one
> > additional issue converting string to JSON object which was solved as
> > follows:
>
> > dojo.xhrGet({
> > url: myurl,
> > handleAs: "json",
> > load: function(response, ioArgs){
> > var myObject = eval('(' + response
> > + ')');
> > myjsfunction(myObject);
> > },
> > error: function(response, ioArgs){
> > alert("An error occurred
> > retrieving the current feed from the
> > server cache.");
> > //dojo.byId("toBeReplaced").innerHTML
> > = "An error occurred,
> > with response: " + response;
> > return response;
> > }
>
> > });
>
> > On Sep 10, 12:52 am, "Peter Svensson" <[EMAIL PROTECTED]> wrote:
>
> > > That's a good example of how jsonp can look like. Also, I wrote the last
> > > post with my head screwed on backwards, I think :) To get jsonp, you can
> > > just use response.out.write('/*'+foo+'*/') where foo is the json string.
>
> > > Cheers,
> > > PS
>
> > > On Tue, Sep 9, 2008 at 10:18 PM, Davide Rognoni <[EMAIL PROTECTED]>wrote:
>
> > > > JSON-P example:
>
> > > > <script>
> > > > function foo(json) {
> > > > alert( json["responseData"]["translatedText"] );
> > > > }
> > > > </script>
>
> > > > <script src="http://ajax.googleapis.com/ajax/services/language/
> > > > translate?v=1.0&q=hello%20world&langpair=en%7Cit&callback=foo<http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=h...>
> > > > "></
> > > > script>
>
> > > > // -------------------------------------
> > > > see the link
> > > >http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=h...
> > > > .
> > > > .
> > > > .
> > > > .
> > > > -- Best Template Engine
> > > >http://pyoohtml.appspot.com/best-template-engine
> > > > .
> > > > .
> > > > .
> > > > .
> > > > On Sep 9, 9:01 am, "Peter Svensson" <[EMAIL PROTECTED]> wrote:
> > > > > 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
-~----------~----~----~----~------~----~------~--~---