我是dojo的新手,我試圖按特定順序指定一個變量。這裏有一個例子:dojo執行順序
require(["dojo/request"], function(request){
var myVar;
request("helloworld.txt").then(
function(text){
myVar = text;
alert(myVar); //2nd alert to display and contains contents of helloworld.txt
},
function(error){
console.log("An error occurred: " + error);
}
);
alert(myVar); //1st alert to display and displays undefined
});
我需要myVar的了「於是」功能的內部分配,然後用它那功能之外。換句話說,我需要第一個警報來包含helloworld.txt的內容。提前致謝!
的可能重複[如何返回從AJAX調用的響應?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) –