On Fri, Mar 8, 2013 at 2:59 AM, Shannon Cruey
<[email protected]> wrote:
> My function is too long to paste here, but this is the (untested) relevant
> lines. I have jsonp callback working with jquery ajax.
>
> def GET(self, method):
> args = web.input()
> web.header('Content-Type', 'application/json')
> payload = json.dumps({'a': 'foo'}) ' # or call some func that return
> serialized data
> return "%s('%s')" % (args["callback"], payload)
>
> I can't find my jquery example, but basically it executes the command you
> got back. callbackfunc(jsondata);
That is the typical pattern that I follow too.
json = simplejson.dumps(result)
web.header('Content-Type', 'text/javascript')
if i.callback:
return "%s(%s);" % (i.callback, json)
else:
return json
Here is a complete example.
https://github.com/internetarchive/openlibrary/blob/master/openlibrary/coverstore/code.py#L422
Anand
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.