source: Dev/trunk/src/client/dojo/rpc/JsonpService.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: 1.8 KB
Line 
1define([
2        "../_base/array", "../_base/declare", "../_base/lang", "./RpcService", "../io/script"],
3        function(array, declare, lang, RpcService, script){
4
5// module:
6//              dojo/rpc/JsonpService
7
8return declare("dojo.rpc.JsonpService", RpcService, {
9        // summary:
10        //              Generic JSONP service.  Minimally extends RpcService to allow
11        //              easy definition of nearly any JSONP style service. Example
12        //              SMD files exist in dojox.data
13
14        constructor: function(args, requiredArgs){
15                if(this.required){
16                        if(requiredArgs){
17                                lang.mixin(this.required, requiredArgs);
18                        }
19
20                        array.forEach(this.required, function(req){
21                                if(req=="" || req==undefined){
22                                        throw new Error("Required Service Argument not found: "+req);
23                                }
24                        });
25                }
26        },
27
28        strictArgChecks: false,
29
30        bind: function(method, parameters, deferredRequestHandler, url){
31                // summary:
32                //              JSONP bind method. Takes remote method, parameters,
33                //              deferred, and a url, calls createRequest to make a JSON-RPC
34                //              envelope and passes that off with bind.
35                // method: string
36                //              The name of the method we are calling
37                // parameters: array
38                //              The parameters we are passing off to the method
39                // deferredRequestHandler: deferred
40                //              The Deferred object for this particular request
41
42                var def = script.get({
43                        url: url||this.serviceUrl,
44                        callbackParamName: this.callbackParamName||"callback",
45                        content: this.createRequest(parameters),
46                        timeout: this.timeout,
47                        handleAs: "json",
48                        preventCache: true
49                });
50                def.addCallbacks(this.resultCallback(deferredRequestHandler), this.errorCallback(deferredRequestHandler));
51        },
52
53        createRequest: function(parameters){
54                // summary:
55                //              create a JSONP req
56                // params: array
57                //              The array of parameters for this request;
58
59                var params = (lang.isArrayLike(parameters) && parameters.length==1) ?
60                                parameters[0] : {};
61                lang.mixin(params,this.required);
62                return params;
63        }
64});
65
66});
Note: See TracBrowser for help on using the repository browser.