/**
* @fucntion:发送AJAX请求
* @author ###
* @date:2006-08-09
* @ver v1.0
*/
//**定义XMLHttpRequest对象实例
var http_request = false;
//** 定义可复用的http请求发送函数
//** @method为发送请求的方式:get,post二种
//** @url为发送目的地址
//** @url为发送的内容
//** @responseType设置响应的格式:text,xml二种
//** @callback回调函数名
function send_request(method,url,content,responseType,callback) {
//**初始化、指定处理函数、发送请求的函数
http_request = false;
//**开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) {
//**Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
//**设置MiME类别
http_request.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) {
//**IE浏览器
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
//**异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
if(responseType.toLowerCase()=="text") {
http_request.onreadystatechange = getReadyStateTextHandler(http_request, callback);
}
else if(responseType.toLowerCase()=="xml") {
http_request.onreadystatechange = getReadyStateXMLHandler(http_request, callback);
}
else {
window.alert("响应类别参数错误。");
return false;
}
//**确定发送请求的方式和URL以及是否异步执行下段代码
if(method.toLowerCase()=="get") {
http_request.open(method, url, true);
}
else if(method.toLowerCase()=="post") {
http_request.open(method, url, true);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
else {
window.alert("http请求类别参数错误。");
return false;
}
http_request.send(content);
}
//**处理返回Text格式信息的函数
function getReadyStateTextHandler(http_request, callback) {
return function () {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
callback(http_request.responseText);
} else {
alert("HTTP error "+http_request.status+": "+http_request.statusText);
}
}
}
}
//**处理返回XML格式信息的函数
function getReadyStateXMLHandler(http_request, callback) {
return function () {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
callback(http_request.responseXML);
} else {
alert("HTTP error "+http_request.status+": "+http_request.statusText);
}
}
}
}
* @fucntion:发送AJAX请求
* @author ###
* @date:2006-08-09
* @ver v1.0
*/
//**定义XMLHttpRequest对象实例
var http_request = false;
//** 定义可复用的http请求发送函数
//** @method为发送请求的方式:get,post二种
//** @url为发送目的地址
//** @url为发送的内容
//** @responseType设置响应的格式:text,xml二种
//** @callback回调函数名
function send_request(method,url,content,responseType,callback) {
//**初始化、指定处理函数、发送请求的函数
http_request = false;
//**开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) {
//**Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
//**设置MiME类别
http_request.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) {
//**IE浏览器
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
//**异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
if(responseType.toLowerCase()=="text") {
http_request.onreadystatechange = getReadyStateTextHandler(http_request, callback);
}
else if(responseType.toLowerCase()=="xml") {
http_request.onreadystatechange = getReadyStateXMLHandler(http_request, callback);
}
else {
window.alert("响应类别参数错误。");
return false;
}
//**确定发送请求的方式和URL以及是否异步执行下段代码
if(method.toLowerCase()=="get") {
http_request.open(method, url, true);
}
else if(method.toLowerCase()=="post") {
http_request.open(method, url, true);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
else {
window.alert("http请求类别参数错误。");
return false;
}
http_request.send(content);
}
//**处理返回Text格式信息的函数
function getReadyStateTextHandler(http_request, callback) {
return function () {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
callback(http_request.responseText);
} else {
alert("HTTP error "+http_request.status+": "+http_request.statusText);
}
}
}
}
//**处理返回XML格式信息的函数
function getReadyStateXMLHandler(http_request, callback) {
return function () {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
callback(http_request.responseXML);
} else {
alert("HTTP error "+http_request.status+": "+http_request.statusText);
}
}
}
}