It's not my first try. I like to find the ultimate way to do this kind of thing. In this approach, I really needed a way to send multiple needs, and to retrieve many results. It's based on jQuery (clientside) and webpy (serverside) (with a json lib like demjson), as always. It's a proof of concept, but it feeds my needs (and perhaps yours)
On the client side, it's a classical ajax method :
function ajax( method, data, callback ) {...}
method define the server side method, data is a classical dict, and callback is a optional callback.
Which does nothing, except returning a object which have got an attribut result which contains 'hellohello'. But the previous client side call don't care about the result.
To use the result on the client side, we should use something like this :
Which should display 'hellohello' in an alert box.
Note, as on the server side, the python method method1 has got a default value for param arg1. It could be possible to call the ajax method without providing a arg1 :
Which should display 'bonjourbonjour' in an alert box.
Until here, it's a very classical ajax method : A call, and a return as a dict. A neat feature is that you can fill html tags on server side. On this simple example, client side :
The div#out1 and div#out2 will be automatically filled with the response of the server method. It use the "[]" trick to encapsulate a jquery selector.
It's just a simple way, to feed some tag on the clientside. Another neat feature is that you can send back a javascript call in your response, by adding a key script in your result like this :
which should feed div#out1 and div#out2, and display an alert box containing '1'.
So it's easy to define javascript calls, or feed a client tag, by doing it on the serverside, in a python way.
But the great feature, is that you can call many methods from the server side in one client ajax call, by passing a list of methods, like this :
method1 will be executed at first, and method2 at last. Each method will try to find its own parameters in the dict. Thus, parameters can be shared between methods.
And better : method1 could set parameters for method2 like this: