/ Published in: Python
                    
                                        
This is a @property to take care of jsonp stuff if you're using CherryPy.
In your Javascript, (you're using JQuery, right?) you can do
`
$.ajax({url:"localhost:8080/MyMethod", data:{'arg1':'foo'}, dataType:"jsonp", success:onMyMethodComplete});
`
and you will get back your JS datastructure without having to worry about the jsonp stuff yourself.
                In your Javascript, (you're using JQuery, right?) you can do
`
$.ajax({url:"localhost:8080/MyMethod", data:{'arg1':'foo'}, dataType:"jsonp", success:onMyMethodComplete});
`
and you will get back your JS datastructure without having to worry about the jsonp stuff yourself.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
import simplejson
def jsonp(func):
def foo(self, *args, **kwargs):
callback, _ = None, None
if 'callback' in kwargs and '_' in kwargs:
callback, _ = kwargs['callback'], kwargs['_']
del kwargs['callback'], kwargs['_']
ret = func(self, *args, **kwargs)
if callback is not None:
ret = '%s(%s)' % (callback, simplejson.dumps(ret))
return ret
return foo
class Server(object):
@cherrypy.expose
@jsonp
def MyMethod(self, arg1):
#do something with arg1
return 'Works'
Comments
 Subscribe to comments
                    Subscribe to comments
                
                