require(["dojo/request"], function(request){ request("helloworld.txt").then( function(text){ console.log("The file's content is: " + text); }, function(error){ console.log("An error occurred: " + error); } ); });
require(["dojo/request"], function(request){ request.post("post-content.php", { data: { color: "blue", answer: 42 }, headers: { "X-Something": "A value" } }).then(function(text){ console.log("The server returned: ", text); }); });
require(["dojo/dom", "dojo/on", "dojo/request", "dojo/domReady!"], function(dom, on, request){ // Results will be displayed in resultDiv var resultDiv = dom.byId("resultDiv"); // Attach the onclick event handler to the textButton on(dom.byId("textButton"), "click", function(evt){ // Request the text file request.get("../resources/text/psalm_of_life.txt").then( function(response){ // Display the text file content resultDiv.innerHTML = "<pre>"+response+"</pre>"; }, function(error){ // Display the error returned resultDiv.innerHTML = "<div class="error">"+error+"<div>"; } ); }); } );
官网地址:http://dojotoolkit.org/documentation/tutorials/1.10/ajax/index.html