]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/rpc/JsonService.js
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dojo.rpc.JsonService"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dojo.rpc.JsonService"] = true;
10 dojo
.provide("dojo.rpc.JsonService");
11 dojo
.require("dojo.rpc.RpcService");
14 dojo
.declare("dojo.rpc.JsonService", dojo
.rpc
.RpcService
, {
16 contentType
: "application/json-rpc",
19 callRemote: function(method
, params
){
21 // call an arbitrary remote method without requiring it to be
22 // predefined with SMD
24 // the name of the remote method you want to call.
26 // array of parameters to pass to method
28 var deferred
= new dojo
.Deferred();
29 this.bind(method
, params
, deferred
);
33 bind: function(method
, parameters
, deferredRequestHandler
, url
){
35 // JSON-RPC bind method. Takes remote method, parameters,
36 // deferred, and a url, calls createRequest to make a JSON-RPC
37 // envelope and passes that off with bind.
39 // The name of the method we are calling
41 // The parameters we are passing off to the method
42 // deferredRequestHandler: deferred
43 // The Deferred object for this particular request
45 var def
= dojo
.rawXhrPost({
46 url
: url
||this.serviceUrl
,
47 postData
: this.createRequest(method
, parameters
),
48 contentType
: this.contentType
,
49 timeout
: this.timeout
,
50 handleAs
: "json-comment-optional"
52 def
.addCallbacks(this.resultCallback(deferredRequestHandler
), this.errorCallback(deferredRequestHandler
));
55 createRequest: function(method
, params
){
57 // create a JSON-RPC envelope for the request
59 // The name of the method we are creating the requst for
61 // The array of parameters for this request;
63 var req
= { "params": params
, "method": method
, "id": ++this.lastSubmissionId
};
64 var data
= dojo
.toJson(req
);
68 parseResults: function(/*anything*/obj
){
70 // parse the result envelope and pass the results back to
71 // the callback function
73 // Object containing envelope of data we recieve from the server
75 if(dojo
.isObject(obj
)){
82 if("ResultSet" in obj
){