关于js调用内部函数,并返回值(附代码)
var SystemInfo = {
//数据源
dsource: " ",
setSource:function(x)
{
this.dsource = x;
},
getXmlDoc:function()
{
var myAjax = new Ajax.Request(this.dsource,{method: 'get ',onComplete:this.getInfo});
},
getInfo:function(x)
{
return x.responseText;
}
}
SystemInfo.setSource( "http://...... ");
var ret = SystemInfo.getXmlDoc();
alert(ret);
这里面用到了prototype,
但是最后得不到x.responseText...
不知哪里出错,请指正
------解决方案--------------------var SystemInfo = {
//数据源
dsource: " ",
setSource:function(x)
{
this.dsource = x;
},
send:function()
{
var myAjax = new Ajax.Request(this.dsource,{method: 'get ',onComplete:this.getInfo});
},
getInfo:function(){}
}
//新实例
var dd = new SystemInfo();
dd.setSource( "http://...... ");
//这里实现委托
dd.getInfo = function(res){
alert(res.responseText);//这里添加处理代码
};
dd.send();//发送
OK?