• dojo.io.script


    dojo.io.script

    定义:

    跨域访问数据,可以动态的将script标签插入到网页当中。

    局限:

    1.只支持get方式访问;

    2.只支持异步调用。

    使用:

    1.dojo.io.script.get() 带一个JavaScript对象参数,这个js对象支持以下属性:

    url:请求的url。

    callbackParamName:url参数名,指示JSONP回调字符串。

    checkString:字符串,默认为null。在已被加载的script中定义的一个变量, that will determine if the request has finished.

    preventCache:一个布尔值,用来告诉dojo.xhrGet为每个请求附加一个特别的查询参数。(可选参数)

    content:一个{name1:string1,name2:string2}组合成JavaScript对象。(可选参数)

    2.返回值

    返回一个“dojo.Deferred”对象。这个对象允许你定义额外的成功和失败的回调。它也可以被用来在你的请求参数中替代定义“load”和“error”方法。

    实例:

     1  function searchGoogle(){
     2    // Look up the node we'll stick the text under.
     3    var targetNode = dojo.byId("results");
     4 
     5    // The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
     6    var jsonpArgs = {
     7      url: "http://ajax.googleapis.com/ajax/services/search/web",
     8      callbackParamName: "callback",
     9      content: {
    10        v: "1.0",
    11        q: "dojo toolkit"
    12      },
    13      load: function(data){
    14        // Set the data from the search into the viewbox in nicely formatted JSON
    15        targetNode.innerHTML = "<pre>" + dojo.toJson(data, true) + "</pre>";
    16      },
    17      error: function(error){
    18        targetNode.innerHTML = "An unexpected error occurred: " + error;
    19      }
    20    };
    21    dojo.io.script.get(jsonpArgs);
    22  }
    23  dojo.ready(searchGoogle);
    //html代码
    <b>Google Search Results for 'dojo toolkit' (In JSON):</b>
    <div id="results" style="height: 200px;"></div>

    http://dojotoolkit.org/reference-guide/1.10/dojo/io/script.html

    http://dojotoolkit.org/reference-guide/1.8/dojo/request/script.html

  • 相关阅读:
    初见线段树
    用typedef声明类型
    BZOJ 3240([Noi2013]矩阵游戏-费马小定理【矩阵推论】-%*s-快速读入)
    linux命令--sysctl
    信号量学习 & 共享内存同步
    原子操作
    共享内存学习
    HOST绑定和VIP映射
    【转载】《Unix网络编程》思维导图
    外排序 & 败者树 & 多路归并-学习
  • 原文地址:https://www.cnblogs.com/myboke/p/4673108.html
Copyright © 2020-2023  润新知