xhrScriptPlugin.js 1.4 KB

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