技术开发 频道

快速、简便的使用AJAX技术操作的三部曲


第二步 :

在页面里加入下面这段javascript代码

var xmlHttp; 

function createXMLHttpRequest(){
if (window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function startAjaxRequest(method,async,actionUrl,data, invokeMethod){
createXMLHttpRequest();
xmlHttp.open(method, actionUrl, async);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(data);

function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var nodeId = xmlHttp.responseText;
if (nodeId=='noPermission'){
alert('你没有权限访问此操作!');
}else if( (falseIndex = nodeId.indexOf("false||"))!= -1 ){
alert('操作失败,可能的原因为:' + nodeId.substring(
falseIndex+7, nodeId.length) + "!");
}else if(nodeId=='false'){
alert('操作失败,请和管理员联系!');
}else ...{
if (invokeMethod == undefined){
getResult(nodeId);
} else {
invokeMethod(nodeId);
}
}
}
}
}
}
  
0
相关文章