var xmlHttp;
// 创建XMLHttpRequest对象
function createXMLHttpRequest() {
try {
// FireFox, Opera 8.0 +, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
try {
// IE 6.0 +
xmlHttp = new ActiveXObject('MSXML2.XMLHTTP');
}
catch (e) {
try {
// IE 5.5 +
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e) {
alert('您的浏览器不支持AJAX!');
return false;
}
}
}
}
function SendContent(url, type, data, handleMethod) {
createXMLHttpRequest();
xmlHttp.open(type, url);
xmlHttp.onreadystatechange = function() { postBack(handleMethod); };
xmlHttp.send(data);
}
function postBack(method) {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
//var result = xmlHttp.responseText; // 返回文本或XML
// 相关数据处理
method();
}
else {
alert('the XMLHttpRequest status is ' + xmlHttp.status);
}
}
}
ajax 通用方法
最新推荐文章于 2021-09-03 09:34:33 发布