我是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) –