source: Dev/branches/rest-dojo-ui/client/dojox/io/xhrScriptPlugin.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.4 KB
Line 
1define(["dojo/_base/kernel", "dojo/_base/window", "dojo/io/script", "dojox/io/xhrPlugins", "dojox/io/scriptFrame"], function(dojo, window, script, xhrPlugins, scriptFrame){
2dojo.getObject("io.xhrScriptPlugin", true, dojox);
3
4dojox.io.xhrScriptPlugin = function(/*String*/url, /*String*/callbackParamName, /*Function?*/httpAdapter){
5        // summary:
6        //              Adds the script transport (JSONP) as an XHR plugin for the given site. See
7        //              dojox.io.script for more information on the transport. Note, that JSONP
8        //              is *not* a secure transport, by loading data from a third-party site using JSONP
9        //              the site has full access to your JavaScript environment.
10        //      url:
11        //              Url prefix of the site which can handle JSONP requests.
12        //      httpAdapter: This allows for adapting HTTP requests that could not otherwise be
13        //              sent with JSONP, so you can use a convention for headers and PUT/DELETE methods.
14        xhrPlugins.register(
15                "script",
16                function(method,args){
17                         return args.sync !== true &&
18                                (method == "GET" || httpAdapter) &&
19                                (args.url.substring(0,url.length) == url);
20                },
21                function(method,args,hasBody){
22                        var send = function(){
23                                args.callbackParamName = callbackParamName;
24                                if(dojo.body()){
25                                        args.frameDoc = "frame" + Math.random();
26                                }
27                                return script.get(args);
28                        };
29                        return (httpAdapter ? httpAdapter(send, true) : send)(method, args, hasBody); // use the JSONP transport
30                }
31        );
32};
33
34return dojox.io.xhrScriptPlugin;
35});
Note: See TracBrowser for help on using the repository browser.