A jsonrpc 2.0 call through jquery to the Tornado web server receives a “200 OK” http response and my network sniffer shows the decoded response as containing
{"jsonrpc": "2.0", "error": null, "result": 3500, "id": "jsonrpc"}
ie valid jsonrpc 2.0 answer. 3500 is also the correct result, RPC was a simple add function.
However, firebug does not display the response and .ajax success . does not start. The answers are .ajax () error and complete . but gave me no idea about the problem. Here's index.html, which calls the ajax () call.
$(document).ready(function(){ $.ajax({ url: 'http://localhost:8080', data: JSON.stringify ({jsonrpc:'2.0',method:'add', params:[1400,2100],id:"jsonrpc"} ), // id is needed !! type:"POST", dataType:"json", success: function (result) { alert("ok"); }, error: function (err,status,thrown) { alert ("this syntax sucks!! " + " ERROR: " + err + " STATUS: " + status + " " + thrown ); }, complete: function (xhr,status) { alert('Complete=> showing status as: '+ status); data = $.parseJSON(xhr.responseText); alert (data); } }); });
source share