AJAX简历系统附js文件

所属分类: 网络编程 / AJAX相关 阅读数: 1530
收藏 0 赞 0 分享
复制代码 代码如下:

/**********************************************
 * @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;
     }
 }    

本地下载
更多精彩内容其他人还在看

PHP+AJAX无刷新实现返回天气预报数据

天气数据是通过采集中国气象网站的。本来中国天气网站也给出了数据的API接口,接下来为大家介绍下用php来写一个天气预报的模块,感兴趣的朋友可以参考下
收藏 0 赞 0 分享

jQuery的ajax传参巧用JSON使用示例(附Json插件)

jQuery的ajax调用很方便,传参的时候喜欢用Json的数据格式,使用示例代码如下,感兴趣的朋友可以参考下,希望对大家有所帮助
收藏 0 赞 0 分享

ajax jquery 异步表单验证示例代码

异步表单验证想必大家早已如雷贯耳,本文为大家详细讲述下ajax jquery实现异步表单验证,感兴趣的朋友可以参考下
收藏 0 赞 0 分享

AJAX如何接收JSON数据示例介绍

如何使用AJAX返回JSON数据,就是dataType,当你设置json后返回的json字符串传递到客户端就是JSON对象了,示例如下,感兴趣的朋友可以参考下
收藏 0 赞 0 分享

ajax局部刷新一个div下jsp内容的方法

局部刷新某个div下的jsp可以通过setInterval或者是setTimeout来轻松实现,具体如下,有此需求的朋友可以参考下,希望对大家有所帮助
收藏 0 赞 0 分享

ajax交互Struts2的action(客户端/服务器端)

本文为大家探讨下ajax交互Struts2的action并有客户端及服务器端代码,感兴趣的朋友可以参考下,希望对大家有所帮助
收藏 0 赞 0 分享

Ajax工作原理深入理解

ajax是异步的意思,它有别于传统web开发中采用的同步的方式。异步传输是面向字符的传输,它的单位是字符;而同步传输是面向比特的传输,它的单位是桢,它传输的时候要求接受方和发送方的时钟是保持一致的
收藏 0 赞 0 分享

Ajax方式删除表格一行数据示例代码

Ajax方式删除信息在某些情况下还是蛮实用的,下面为大家具体介绍下Ajax方式如何删除表格一行数据,感兴趣的朋友可以了解下
收藏 0 赞 0 分享

Ajax叠加(Ajax返回数据用Ajax发出)示例代码

把参数用Ajax发送到数据库进行查询然后用Ajax将数据发送到数据库签到表,于是有了下面的代码,感兴趣的朋友可以了解下,希望对大家学习ajax有所帮助
收藏 0 赞 0 分享

Ajax长连接项目案例

所谓的长连接,就是不断去发送请求,把请求阻塞在服务器端,每次超过请求时间就去重新发送请求,下面以一个实例为大家详细介绍下,感兴趣的朋友可不要错过了哈
收藏 0 赞 0 分享
查看更多