AJAX如何实现简历系统

发布时间:2021-10-13 15:29:11 作者:小新
来源:亿速云 阅读:117

这篇文章主要为大家展示了“AJAX如何实现简历系统”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“AJAX如何实现简历系统”这篇文章吧。

代码如下:


/**********************************************
 * @function    javascript client ajax dealwith
 **********************************************    
 * 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;
     }
 }    

以上是“AJAX如何实现简历系统”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. 用bootstrap制作简历的方法
  2. Vue+Element如何实现网页版个人简历系统

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ajax

上一篇:如何实现Netfilter

下一篇:如何编写代码实现股票买卖

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》