欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

AJAX简历系统附js文件

程序员文章站 2022-05-03 08:04:59
复制代码 代码如下:/**********************************************  * @author &n...
复制代码 代码如下:

/**********************************************
 * @author        skyz
 * @function    javascript client ajax dealwith
 * @datetime    2006-3-20
 **********************************************    
 * function: create a httprequest object
 **********************************************/ 
function httprequest(){
    this._httprequest=null;                                    //httprequest request object
    this._callback=null;                                    //call back function
    this._domresult=true;                                    //result if dom object or text string
    this._requestdata=null;                                    //request data
    this._requestresult=null;                                //httprequest result
    this._statestring=null;                                    //current request state string
    this._error=false;                                        //current if have error
    this._callbackpara=null;                                //current callback function parama
    //internal method for get httprequestobject
    this.init=function(){
        //judge if not ie
        if(window.xmlhttprequest){
            this._httprequest=new xmlhttprequest();
            //set request mime is text/xml
            if(this._httprequest.overridemimetype){
                this._httprequest.overridemimetype('text/xml');
            }
        }else if(window.activexobject){
            try{
                this._httprequest=new activexobject("msxml2.xmlhttp");
            }catch(ex){
                try{
                    this._httprequest=new activexobject("microsoft.xmlhttp");
                }catch(ex){
                    this._setmessage(ex,true);
                    return;
                }
            }
                // this._httprequest.setrequestheader("content-type","text/xml;charset=gb2312");
        }
        //judge httprequest object create successful
        if(!this._httprequest){
            this._setmessage("xmlhttprequest 对象创建失败!请重试......",true);
            return;
        }    
    }
    /*    
     * function: set the request header
     * namepar:request's header name
     * valuepar:request's header value
     */
    this.dosetrequestheader=function(namepar,valuepar){
        if(this._error){
            return;
        }
        this._httprequest.setrequestheader(namepar,valuepar);
    }
    /*    
     * function: set the request data
     * datapar:request's send data;
     */
    this.dosetrequestdata=function(datapar){
        if(this._error){
            return;
        }
        this._requestdata=datapar;
    }
    /*
     *function get requesthttp object
    */
    this._getrequestobj=function(){
        if(this._error){
            return;
        }
        return this._httprequest;
    }
    /*
     * function:set callback function para
     */
    this.dosetcallback=function(callback,paradata){
        this._callback=(callback)?callback:null;
        this._callbackpara=(paradata)?paradata:null;
    };
    /*
     * function: get current statestring
     */
    this.dogetstate=function(){
        return this._statestring;
     }
     /*
     * function: get current error 
     */
    this.dogeterror=function(){
        return this._error;
     }
     /*
      *
       */
    this.docallback=function(){
        this._callback(this._requestresult,this._callbackpara);
    }

    /*    
     * function: send the request
     * urlpar: request's url path
     * [methodpar]:request's method
     * [dompar]: request's result is dom or string
     */
    this.dosendresuest=function(urlpar,methodpar,obj,dompar,asypar){
        if(obj._error){
            return;
        }
        methodpar=((methodpar)?methodpar:"get");
        asypar=((asypar)?asypar:true);
        this._domresult=(dompar)?dompar:obj._domresult;
        try{
                var a=this._getrequestobj();
                a.onreadystatechange=function(){
                    if(obj._error){
                        return;
                    }
                    var readystatetmp=a.readystate;
                    if(readystatetmp==0){
                        obj._setmessage("未初始化!");
                    }else if(readystatetmp==1){
                        obj._setmessage("正在读取中......");
                    }else if(readystatetmp==2){
                        obj._setmessage("已经读取过!");
                    }else if(readystatetmp==3){
                        obj._setmessage("正在逐个切换......");
                    }else if(readystatetmp==4){
                        var statustmp=a.status;
                        if(statustmp==404){
                            obj._setmessage("未找到请求页面!",true);
                        }else if(window.location.href.indexof("http")==-1 || statustmp==200){
                            obj._setmessage("完成!");    
                            if(this._domresult && window.xmlhttprequest){
                                obj._requestresult=a.responsexml;
                            }else{
                                obj._requestresult=a.responsetext;
                            }
                            if(obj._callback){
                                obj.docallback();
                            }
                        }else{
                            obj._setmessage("未知错误!");
                        }
                    }else{
                        obj._setmessage("未知错误!");
                    }    
                }
            a.open(methodpar,urlpar,asypar);
            // a.setrequestheader("if-modified-since","0");
            a.send(obj._requestdata);
        }catch(ex){
            obj._setmessage(ex,true);
        }
    }
    /*
     * function: deal exception error 
     * expar:error string
     */
    this._setmessage=function(expar,mark){
        this._statestring=expar.tostring();
        this._error=(mark)?mark:false;
     }
 }