1 define("dojo/rpc/JsonService", [
2 "../_base/declare", "../_base/Deferred", "../_base/json", "../_base/lang", "../_base/xhr",
4 ], function(declare, Deferred, json, lang, xhr, RpcService){
7 // dojo/rpc/JsonService
9 return declare("dojo.rpc.JsonService", RpcService, {
14 contentType: "application/json-rpc",
17 callRemote: function(method, params){
19 // call an arbitrary remote method without requiring it to be
20 // predefined with SMD
22 // the name of the remote method you want to call.
24 // array of parameters to pass to method
26 var deferred = new Deferred();
27 this.bind(method, params, deferred);
31 bind: function(method, parameters, deferredRequestHandler, url){
33 // JSON-RPC bind method. Takes remote method, parameters,
34 // deferred, and a url, calls createRequest to make a JSON-RPC
35 // envelope and passes that off with bind.
37 // The name of the method we are calling
39 // The parameters we are passing off to the method
40 // deferredRequestHandler: deferred
41 // The Deferred object for this particular request
44 url: url||this.serviceUrl,
45 postData: this.createRequest(method, parameters),
46 contentType: this.contentType,
47 timeout: this.timeout,
48 handleAs: "json-comment-optional"
50 def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler));
53 createRequest: function(method, params){
55 // create a JSON-RPC envelope for the request
57 // The name of the method we are creating the request for
59 // The array of parameters for this request
61 var req = { "params": params, "method": method, "id": ++this.lastSubmissionId };
62 return json.toJson(req);
65 parseResults: function(/*anything*/obj){
67 // parse the result envelope and pass the results back to
68 // the callback function
70 // Object containing envelope of data we receive from the server
72 if(lang.isObject(obj)){
79 if("ResultSet" in obj){