javascript dojo全局变量无法赋值 15
functionbitianxiangPD(){varb="";varparams=newArray();params['func']="nh";params['num1...
function bitianxiangPD(){
var b = "" ;
var params = new Array();
params['func'] = "nh";
params['num1'] = document.nhForm.id.value;
var bindArgs = {
url: "com.text.nh.NhServlet",
error: function(type, data, evt){alert("失败");},
load: function(type, data, evt){
var List = data.getElementsByTagName("nhListXml")[0];
var items = List.getElementsByTagName("item");
if(items.length==0){
b+= "true";
}else{
b+= "false";
}
},
mimetype: "text/xml",
encoding: "utf-8",
preventCache: true,
useCache:false,
content: params
};
dojo.io.bind(bindArgs);
return b;
}
b的值为什么没变化,不能赋值??? 展开
var b = "" ;
var params = new Array();
params['func'] = "nh";
params['num1'] = document.nhForm.id.value;
var bindArgs = {
url: "com.text.nh.NhServlet",
error: function(type, data, evt){alert("失败");},
load: function(type, data, evt){
var List = data.getElementsByTagName("nhListXml")[0];
var items = List.getElementsByTagName("item");
if(items.length==0){
b+= "true";
}else{
b+= "false";
}
},
mimetype: "text/xml",
encoding: "utf-8",
preventCache: true,
useCache:false,
content: params
};
dojo.io.bind(bindArgs);
return b;
}
b的值为什么没变化,不能赋值??? 展开
1个回答
展开全部
你的load函数里面是异步的,
执行顺序错了
应该return b 改成一个回调函数放在load:function(){}里面最后
执行顺序错了
应该return b 改成一个回调函数放在load:function(){}里面最后
更多追问追答
追问
具体怎么完成??不太明白。。。
追答
function bitianxiangPD(){
var b = "" ;
var params = new Array();
params['func'] = "nh";
params['num1'] = document.nhForm.id.value;
var bindArgs = {
url: "com.text.nh.NhServlet",
error: function(type, data, evt){alert("失败");},
load: function(type, data, evt){
var List = data.getElementsByTagName("nhListXml")[0];
var items = List.getElementsByTagName("item");
if(items.length==0){
b+= "true";
}else{
b+= "false";
}
foo(b);
},
mimetype: "text/xml",
encoding: "utf-8",
preventCache: true,
useCache:false,
content: params
};
dojo.io.bind(bindArgs);
}
function foo(b){
alert(b);
//......
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询