I tried to use MochiKit with the jsonrpc.py module that uses JSON-RPC.
I wanted to have interoperability with jsolait, which uses the JSON-RPC protocol. Others may want this too, or may want to migrate from jsolait to MochiKit.
The addition of the following two functions to MochiKit.Async seems to do the trick for me:
var postSimpleXMLHttpRequest = function (url, argdict) {
var self = MochiKit.Async;
var req = self.getXMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
return self.sendXMLHttpRequest(req,argdict);
};
var postJSONDoc = function (url, argdict) {
var self = MochiKit.Async;
var d = postSimpleXMLHttpRequest(url, serializeJSON(argdict));
d = d.addCallback(self.evalJSONRequest);
return d;
};
I tested this with the jsonrpc.py module (from jsolait.net) and it interoperates just fine. Haven't beat it up with heavy testing, but so far "it works for me".
trypost = function(url, argdict) {
var d = postJSONDoc(url,argdict);
d.addCallbacks(function(data){ writeln(inspect(data));}, function(err) { writeln(interpreterManager.showError(err))})
}
trypost('http://my/server/jsonrpc/testj.py',
{'method':'echo',
'params': Yay! It works!?,
'id': 444});