function ajaxReq()
{
var url=null;//服务器端的处理页面地址
var reqResult=null; //服务器端处理后的结果
var rdstate=null; //状态信息
this.doSendResuest=function(_url)
{
url=_url;
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("post",url,true);
xmlHttp.send(null);
if (xmlHttp.readyState == 1)
{
rdstate="正在读取信息.\n";
}
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status==200)
{
rdstate+="更新完成\n";
reqResult=xmlHttp.responseText;
}
}
}
}
this.getState=function() //获取状态信息
{
return rdstate;
}
this.getResult=function() //获取返回结果TEXT
{
return reqResult;
}
}
function ajaxProcess()
{
var e=window.event.srcElement;
var selindex=e.options[e.selectedIndex].value;
var url= window.location.href +"?value="+selindex;
var obj=new ajaxReq();
obj.doSendResuest(url);
var rdstate=obj.getState();
alert(rdstate);
var reqResult=obj.getResult();
alert(reqResult);
var rdstate=obj.getState();
doresult(reqResult,rdstate);
}
这是最基本的封装,有时间再改进下.
{
var url=null;//服务器端的处理页面地址
var reqResult=null; //服务器端处理后的结果
var rdstate=null; //状态信息
this.doSendResuest=function(_url)
{
url=_url;
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("post",url,true);
xmlHttp.send(null);
if (xmlHttp.readyState == 1)
{
rdstate="正在读取信息.\n";
}
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status==200)
{
rdstate+="更新完成\n";
reqResult=xmlHttp.responseText;
}
}
}
}
this.getState=function() //获取状态信息
{
return rdstate;
}
this.getResult=function() //获取返回结果TEXT
{
return reqResult;
}
}
function ajaxProcess()
{
var e=window.event.srcElement;
var selindex=e.options[e.selectedIndex].value;
var url= window.location.href +"?value="+selindex;
var obj=new ajaxReq();
obj.doSendResuest(url);
var rdstate=obj.getState();
alert(rdstate);
var reqResult=obj.getResult();
alert(reqResult);
var rdstate=obj.getState();
doresult(reqResult,rdstate);
}