/*********************
** Name: Ajax base class
** Author: Xiaoqiang Wang
** Date: 2007-12-09
**
** Called As:
**function sc() {
** new defBoroAjax( "server.asp", "id=Ajax", "post", $ajax("in") ).run();
** // parameters: URL, Parameters, RequestMethod, of whose innerHTML
**}
*********************/
function BoroAjax( url, params, opMethod ) {
this.url = url;
this.params = params;
this.opMethod = opMethod.toUpperCase();
this.xmlHttp = false;
this.getAjaxObj = function( ) {
var xmlHttp;
try { xmlHttp = new XMLHttpRequest (); }
catch( e ) { try { xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" ); }
catch( e ) { try { xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" ); }
catch( e ) {
alert( "Not Support Ajax!" );
xmlHttp = null;
} } }// three catch
return xmlHttp;
};
this.setXmlHttp = function( ) {
this.xmlHttp = this.getAjaxObj( );
};
this.getRequest = function( targetObj ) {
var http = this.xmlHttp;
http.onreadystatechange = function( ) {
if ( http.readyState == 4 && http.status == 200 ) {
targetObj.innerHTML = http.responseText;
}
};
http.open( "GET", this.url + "?" + this.params , true );
http.send( null );
return true;
};
this.postRequest = function( targetObj ) {
var http = this.xmlHttp;
http.open("POST", url, true);
//Send the proper header infomation along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function () {
if ( http.readyState == 4 && http.status == 200 ) {
targetObj.innerHTML = http.responseText;
}
};
http.send( this.params );
};
}
function defBoroAjax( url, params, opMethod, targetObj ) {
this.url = url;
this.params = params;
this.opMethod = opMethod.toUpperCase();
this.targetObj = targetObj;
this.boro = new BoroAjax( this.url, this.params, this.opMethod );
this.run = function( ) {
var b = this.boro;
b.setXmlHttp( );
if( this.opMethod == "GET" )
b.getRequest( this.targetObj );
else if( this.opMethod == "POST" )
b.postRequest( this.targetObj );
else return false;
};
}
function $ajax( vid ) {
return document.getElementById ? document.getElementById( vid ) : document.all.vid;
}
没有合适的资源?快使用搜索试试~ 我知道了~
Ajax操作类,Ajax操作类Ajax操作类
资源详情
资源评论
资源推荐
收起资源包目录
BoroAjax.zip (1个子文件)
BoroAjax.js 2KB
共 1 条
- 1
yztangpeng
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0