1 if(!dojo._hasResource["dojo.rpc.JsonService"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.rpc.JsonService"] = true;
3 dojo.provide("dojo.rpc.JsonService");
4 dojo.require("dojo.rpc.RpcService");
6 dojo.declare("dojo.rpc.JsonService", dojo.rpc.RpcService, {
8 contentType: "application/json-rpc",
11 callRemote: function(method, params){
13 // call an arbitrary remote method without requiring it to be
14 // predefined with SMD
16 // the name of the remote method you want to call.
18 // array of parameters to pass to method
20 var deferred = new dojo.Deferred();
21 this.bind(method, params, deferred);
25 bind: function(method, parameters, deferredRequestHandler, url){
27 // JSON-RPC bind method. Takes remote method, parameters,
28 // deferred, and a url, calls createRequest to make a JSON-RPC
29 // envelope and passes that off with bind.
31 // The name of the method we are calling
33 // The parameters we are passing off to the method
34 // deferredRequestHandler: deferred
35 // The Deferred object for this particular request
37 var def = dojo.rawXhrPost({
38 url: url||this.serviceUrl,
39 postData: this.createRequest(method, parameters),
40 contentType: this.contentType,
41 timeout: this.timeout,
42 handleAs: "json-comment-optional"
44 def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler));
47 createRequest: function(method, params){
49 // create a JSON-RPC envelope for the request
51 // The name of the method we are creating the requst for
53 // The array of parameters for this request;
55 var req = { "params": params, "method": method, "id": ++this.lastSubmissionId };
56 var data = dojo.toJson(req);
60 parseResults: function(/*anything*/obj){
62 // parse the result envelope and pass the results back to
63 // the callback function
65 // Object containing envelope of data we recieve from the server
67 if(dojo.isObject(obj)){
74 if("ResultSet" in obj){