xhrScriptPlugin.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.io.xhrScriptPlugin"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.io.xhrScriptPlugin"] = true;
  8. dojo.provide("dojox.io.xhrScriptPlugin");
  9. dojo.require("dojox.io.xhrPlugins");
  10. dojo.require("dojo.io.script");
  11. dojo.require("dojox.io.scriptFrame");
  12. dojox.io.xhrScriptPlugin = function(/*String*/url, /*String*/callbackParamName, /*Function?*/httpAdapter){
  13. // summary:
  14. // Adds the script transport (JSONP) as an XHR plugin for the given site. See
  15. // dojox.io.script for more information on the transport. Note, that JSONP
  16. // is *not* a secure transport, by loading data from a third-party site using JSONP
  17. // the site has full access to your JavaScript environment.
  18. // url:
  19. // Url prefix of the site which can handle JSONP requests.
  20. // httpAdapter: This allows for adapting HTTP requests that could not otherwise be
  21. // sent with JSONP, so you can use a convention for headers and PUT/DELETE methods.
  22. dojox.io.xhrPlugins.register(
  23. "script",
  24. function(method,args){
  25. return args.sync !== true &&
  26. (method == "GET" || httpAdapter) &&
  27. (args.url.substring(0,url.length) == url);
  28. },
  29. function(method,args,hasBody){
  30. var send = function(){
  31. args.callbackParamName = callbackParamName;
  32. if(dojo.body()){
  33. args.frameDoc = "frame" + Math.random();
  34. }
  35. return dojo.io.script.get(args);
  36. }
  37. return (httpAdapter ? httpAdapter(send, true) : send)(method, args, hasBody); // use the JSONP transport
  38. }
  39. );
  40. };
  41. }