source: Dev/trunk/src/client/dojo/rpc/JsonService.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.4 KB
Line 
1define([
2        "../_base/declare", "../_base/Deferred", "../_base/json", "../_base/lang", "../_base/xhr",
3        "./RpcService"
4], function(declare, Deferred, json, lang, xhr, RpcService){
5
6        // module:
7        //              dojo/rpc/JsonService
8
9        return declare("dojo.rpc.JsonService", RpcService, {
10                // summary:
11                //              TODOC
12
13                bustCache: false,
14                contentType: "application/json-rpc",
15                lastSubmissionId: 0,
16
17                callRemote: function(method, params){
18                        // summary:
19                        //              call an arbitrary remote method without requiring it to be
20                        //              predefined with SMD
21                        // method: string
22                        //              the name of the remote method you want to call.
23                        // params: array
24                        //              array of parameters to pass to method
25
26                        var deferred = new Deferred();
27                        this.bind(method, params, deferred);
28                        return deferred;
29                },
30
31                bind: function(method, parameters, deferredRequestHandler, url){
32                        // summary:
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.
36                        // method: string
37                        //              The name of the method we are calling
38                        // parameters: array
39                        //              The parameters we are passing off to the method
40                        // deferredRequestHandler: deferred
41                        //              The Deferred object for this particular request
42
43                        var def = xhr.post({
44                                url: url||this.serviceUrl,
45                                postData: this.createRequest(method, parameters),
46                                contentType: this.contentType,
47                                timeout: this.timeout,
48                                handleAs: "json-comment-optional"
49                        });
50                        def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler));
51                },
52
53                createRequest: function(method, params){
54                        // summary:
55                        //              create a JSON-RPC envelope for the request
56                        // method: string
57                        //              The name of the method we are creating the request for
58                        // params: array
59                        //              The array of parameters for this request
60
61                        var req = { "params": params, "method": method, "id": ++this.lastSubmissionId };
62                        return json.toJson(req);
63                },
64
65                parseResults: function(/*anything*/obj){
66                        // summary:
67                        //              parse the result envelope and pass the results back to
68                        //              the callback function
69                        // obj: Object
70                        //              Object containing envelope of data we receive from the server
71
72                        if(lang.isObject(obj)){
73                                if("result" in obj){
74                                        return obj.result;
75                                }
76                                if("Result" in obj){
77                                        return obj.Result;
78                                }
79                                if("ResultSet" in obj){
80                                        return obj.ResultSet;
81                                }
82                        }
83                        return obj;
84                }
85        });
86
87});
Note: See TracBrowser for help on using the repository browser.