---------------------------------------------------------------------------
--1.创建XMLHTTPRequest对象:
function createRequest()
{
var request=null;
if(window.XMLHttpRequest)
{
request=XMLHttpRequest();
}
else if(window.ActiveXObject)
{
request=new ActiveXObject("Msxml2.XMLHTTP");
if(request==null)
{
request=new ActiveXObject("Msxml.XMLHTTP");
}
}
return request;
}
===========================================================================
--2.---------------------------------------------------------------------------------------------------
httpRequest(oRequest,reqType,url,isAsynch,handleResponse,postedData)
{
try
{
if(oRequest==null) return false;
initReq(oRequest,reqType,url,isAsynch,handleResponse,postedData);
}
catch(error)
{
alert("The application cannot contact the server at the moment.Please try again in a few seconds .Error detail:"+error.message);
}
}
-----------------------------------------------------------------------------------------------------
function initReq(oRequest,reqType,url,isAsynch,handleResponse,postedData)
{
if(oRequest==null) return false;
oRequest.onreadyStateChange=handleResponse;
oRequest.open(reqType,url,isAsynch);
if(reqType.toLowerCase()=="post")
{
oRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
oRequest.send(postedData);
}
else if(reqType.toLowerCase()=="get"))
{
oRequest.send(null);
}
else
{
alert("reqType请求类型仅限于GET or POST!!!"+"您的请求类型为"+reqType+"。请检查修正!!");
}
}