function chk_authcode(v){
var a=new ajax(); 
a.URLString="";
a.method="get";
a.onCompletion=function(){
if(a.response=="1"){
return false;
}else if(a.response=="0"){
return true;
}
}
a.Send("q=ajax_authcode&authcode="+v);
}
function chk_submit(){
var authcode=document.getElementById("authcode").value;
if(!chk_authcode(authcode)){
return false;
}
}
第一个函数通过AJAX判断验证码是否正确,没有问题,问题在下面个函数,下面个函数的作用是判断如果验证码错误,则不能触发提交事件,问题出现了,就是验证码不管是对是错都不能触发提交事件,请问这是什么原因?谢谢

解决方案 »

  1.   

    if(a.response=="1"){
      return false;
    }else if(a.response=="0"){
      return true;
    }在这个位置设定的返回值并没有成功,返回为undefinde,请问这个是什么原因造成的?
      

  2.   

    你的ajax函数发给我看看function chk_submit(){
       var authcode=document.getElementById("authcode").value;
        if(!chk_authcode(authcode)){
           return false;
        }
        return true;
    }
      

  3.   

    /** 
    AJAX类库
    @appellation    AJAX
    @date           2010-12-12
    */ 
    function ajax() 

        /** 
        成员变量 
        */ 
        this.XMLHttpReq = null;                     //XML对象 
        this.method = "post";                       //执行的方法(post/get) 
        this.URLString = "";                        //异步调用的页面地址 
        this.response = "";                         //异步返回的响应字符串 
        this.responseXML = "";                      //异步返回的响应XML 
        this.failed = false;                        //创建对象错误标志 
         
        /** 
        事件区 
        */ 
        this.onLoading = function() { };            //正在发送请求 
        this.onLoaded = function() { };             //已经接收到全部响应内容 
        this.onInteractive = function() { };        //正在解析响应内容 
        this.onCompletion = function() { };         //响应内容解析完成 
        this.onError = function() { };              //异步错误处理事件 
        this.onFail = function() { };               //创建对象失败处理世界 
         
        /** 
        重置所有事件函数 
        */ 
        this.resetFunctions = function() { 
            this.onLoading = function() { }; 
            this.onLoaded = function() { }; 
            this.onInteractive = function() { }; 
            this.onCompletion = function() { }; 
            this.onError = function() { }; 
            this.onFail = function() { }; 
        }; 
         
        /** 
        初始化函数(构造时自动初始化) 
        */ 
        this.Init = function() 
        { 
           //对于Mozilla浏览器 
            if(window.XMLHttpRequest) 
            { 
                //直接使用XMLHttpRequest函数来创建XMLHttpRequest对象 
                this.XMLHttpReq = new XMLHttpRequest(); 
            } 
            //对于IE浏览器 
            else if (window.ActiveXObject) 
            { 
                try 
                { 
                    this.XMLHttpReq = new ActiveXObject("Msxml4.XMLHTTP"); 
                } 
                catch(e) 
                { 
                    try 
                    { 
                        this.XMLHttpReq = new ActiveXObject("Msxml3.XMLHTTP"); 
                    } 
                    catch(e) 
                    { 
                        try 
                        { 
                            this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); 
                        } 
                        catch(e) 
                        { 
                            try 
                            { 
                                this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
                            }  
                            catch(oc) 
                            { 
                                this.failed=true;   //创建AJAX对象发生异常 
                            } 
                        } 
                    } 
                } 
                try 
                { 
                    //使用AcitveXObject函数创建浏览器 
                    this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); 
                } 
                catch (e) 
                { 
                    //如果出现异常,再次尝试以如下方式创建XMLHttpRequest对象 
                    try 
                    { 
                        this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
                    } 
                    catch (e) 
                    { 
                        this.failed=true;   //创建AJAX对象发生异常 
                    } 
                } 
            } 
        }; 
         
        /** 
        发送请求函数 
        @param data 发送的数据 
        @example send("id=1"); 
        */ 
        this.Send=function(data) 
        { 
            var self=this; 
            //通过open方法取得与服务器的连接 
            if(this.method=="post") 
            { 
                this.XMLHttpReq.open(self.method,self.URLString,true); 
            } 
            else 
            { 
                this.XMLHttpReq.open(self.method,self.URLString+"?"+encodeURI(data),true); 
            } 
            //添加消息响应头 
            this.XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
             
            //异步回调函数 
            this.XMLHttpReq.onreadystatechange = function() 
            { 
                //对象未创建 
                if (self.failed) { 
                    self.onFail(); 
                    return; 
                } 
                 
                //消息响应标志 
                switch (self.XMLHttpReq.readyState) { 
                    case 1: 
                    { 
                        self.onLoading(); 
                        break; 
                    } 
                    case 2: 
                    { 
                        self.onLoaded(); 
                        break; 
                    } 
                    case 3: 
                    { 
                        self.onInteractive(); 
                        break; 
                    } 
                    case 4: 
                    { 
                        if(self.XMLHttpReq.status==200) {  
                            self.response = self.XMLHttpReq.responseText; 
                            self.responseXML = self.XMLHttpReq.responseXML; 
                            self.onCompletion(); 
                        } 
                        else  
                        {  
                            self.onError();     //执行错误函数 
                        } 
                        break; 
                    } 
                } 
            }; 
             
             
            if(this.method=="post") 
            { 
                this.XMLHttpReq.send(encodeURI(data)); //发送请求 
            } 
            else 
            { 
                this.XMLHttpReq.send(); //发送请求 
            } 
        }; 
         
        this.Abort=function() 
        { 
            this.XMLHttpReq.abort(); 
        } 
         
        this.Close=function() 
        { 
            this.XMLHttpReq=null; 
        } 
        //初始化AJAX库 
        this.Init(); 
    }
      

  4.   

    你if else都不会写啊 ??  else后面怎么又有if   有了也没结尾,???  自己好好看看?   直接else不就可以了,还有你的返回值为underfind的话,说明ajax处理出问题了,这个判断false  true时ajax有问题了,建议看2楼朋友的方法,你需要改下ajax  然后就是我说的if  else  地方