jquery-json-rpc2
A simple JSON-RPC2 library for jquery. This plugin is compatible with the JSON-RPC2 specification and supports basic authentication.
If you want to use authentication, the server must support the OPTIONS preflight request, and it should return the Access-Control-Allow-Headers
header with the value Accept, Authorization, Content-Type
, along with the Content-Length
header, set to the value 0
.
A known server library which wotks with this is node-jsonrpc2 for node.js.
Initializing
To initialize the library call the function $.jsonrpcSetup
with the url, and optionally, username and password for basic authentication
$.jsonrpcSetup(url [, username, password]);
To do a request after setting up the rpc, call $.jsonrpc
, passing method name, an array of parameters to pass and a callback function, which will receive the returned arguments
$.jsonrpc(method, params, callback);
Doing a notification requires the same arguments as a regular RPC call, but don't expect any arguments to your callback function
$.jsonrpcNotify(method, params, callback);