]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/rpc/JsonService.js.uncompressed.js
1 define("dojo/rpc/JsonService", ["../main", "./RpcService"], function(dojo
) {
3 // dojo/rpc/JsonService
8 dojo
.declare("dojo.rpc.JsonService", dojo
.rpc
.RpcService
, {
10 contentType
: "application/json-rpc",
13 callRemote: function(method
, params
){
15 // call an arbitrary remote method without requiring it to be
16 // predefined with SMD
18 // the name of the remote method you want to call.
20 // array of parameters to pass to method
22 var deferred
= new dojo
.Deferred();
23 this.bind(method
, params
, deferred
);
27 bind: function(method
, parameters
, deferredRequestHandler
, url
){
29 // JSON-RPC bind method. Takes remote method, parameters,
30 // deferred, and a url, calls createRequest to make a JSON-RPC
31 // envelope and passes that off with bind.
33 // The name of the method we are calling
35 // The parameters we are passing off to the method
36 // deferredRequestHandler: deferred
37 // The Deferred object for this particular request
39 var def
= dojo
.rawXhrPost({
40 url
: url
||this.serviceUrl
,
41 postData
: this.createRequest(method
, parameters
),
42 contentType
: this.contentType
,
43 timeout
: this.timeout
,
44 handleAs
: "json-comment-optional"
46 def
.addCallbacks(this.resultCallback(deferredRequestHandler
), this.errorCallback(deferredRequestHandler
));
49 createRequest: function(method
, params
){
51 // create a JSON-RPC envelope for the request
53 // The name of the method we are creating the requst for
55 // The array of parameters for this request;
57 var req
= { "params": params
, "method": method
, "id": ++this.lastSubmissionId
};
58 return dojo
.toJson(req
);
61 parseResults: function(/*anything*/obj
){
63 // parse the result envelope and pass the results back to
64 // the callback function
66 // Object containing envelope of data we recieve from the server
68 if(dojo
.isObject(obj
)){
75 if("ResultSet" in obj
){
84 return dojo
.rpc
.JsonService
;