在getInfo函数里,加上alert(x.responseText)能够得到正确的值,但是return后似乎就得不到x.responseText的值,也就是后面的alert(ret)是undefined

解决方案 »

  1.   

    ret当然是undefined
    ...
    getXmlDoc:function()
    {
    var myAjax = new Ajax.Request(this.dsource,{method:'get',onComplete:this.getInfo});
    },
    ...
    这里又没有返回任何值,这样还差不多:getXmlDoc:function()
    {
    return new Ajax.Request(this.dsource, {method:'get',onComplete:this.getInfo});
    },
      

  2.   

    你用的是AJAX吧,这个是异步过程,你要获得responseText的值只能在
    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4&&xmlHttp.status==200){
    dataCount = xmlHttp.responseText;
        }
    }
    这里获得,否则像你那样调用的话他不等值返回回来程序就执行过去了,当然是undefined了
      

  3.   

    对shuangbaby:
      你那样返回的是一个object,并不是我所需要的ajax请求返回的值对element_wm:
      这里用到prototype框架,所以在getInfo()中就能够得到返回值
      我在getInfo()函数第一行添上alert(x.responseText)就可以得到需要的值,然后后面再return,在后面调用getInfo()就得不到值了,
    还请再指教
      

  4.   

    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?
      

  5.   

    多谢 ,问题已经解决 ...只是似乎这一句var dd = new SystemInfo();在firefox下提示:
    SystemInfo is not a constructor这样子,删了这句,直接用SystemInfo即可
      

  6.   

    我看错了,以为你那个是类~`原来是object