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;
}
}
上一篇: 强烈推荐 - Ajax 技术资源中心
下一篇: AJAX防止页面缓存的代码
推荐阅读
-
Node.js 使用substr函数从路径截取文件名称(依赖os组件库区分系统)
-
Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
-
Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
-
Node.js如何响应Ajax的POST请求并且保存为JSON文件详解
-
Node.js如何响应Ajax的POST请求并且保存为JSON文件详解
-
利用Vue.js框架实现火车票查询系统(附源码)
-
node.js常用的fs文件系统
-
Node.JS文件系统解析实例详解
-
Win10预览版10525去水印工具下载 不修改系统文件 附工具用法
-
Ajax客户端异步调用服务端的实现方法(js调用cs文件)