跨域訪問數據,能夠動態的將script標籤插入到網頁當中。html
1.只支持get方式訪問;node
2.只支持異步調用。web
1.dojo.io.script.get() 帶一個JavaScript對象參數,這個js對象支持如下屬性:ajax
url:請求的url。json
callbackParamName:url參數名,指示JSONP回調字符串。api
checkString:字符串,默認爲null。在已被加載的script中定義的一個變量, that will determine if the request has finished.跨域
preventCache:一個布爾值,用來告訴dojo.xhrGet爲每一個請求附加一個特別的查詢參數。(可選參數)異步
content:一個{name1:string1,name2:string2}組合成JavaScript對象。(可選參數)ide
2.返回值jsonp
返回一個「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