Hi, maybe this help to somebody.

i'm developing a webapp with restful interface. But i need cross-site
json, then begin with jsonp.
But web2py don't support generic.jsonp for urls like
http://server:port/app/file/controller.jsonp

i did this creating a new file generic.jsonp in views with this content:

{{
###
# response._vars contains the dictionary returned by the controller action
###
try:
       from gluon.serializers import json
       result = "%s(%s)" % (request.vars['callback'], json(response._vars))
       response.write(result, escape=False)
       response.headers['Content-Type'] = 'application/jsonp'
except (TypeError, ValueError):
       raise HTTP(405, 'JSON serialization error')
except ImportError:
       raise HTTP(405, 'JSON not available')
except:
       raise HTTP(405, 'JSON error')
}}

Cheers!

Reply via email to