ajax|异步
/*
作者:welfred
时间:05年8月14日
作用:Ajax异步调用框架
*/
var req;
// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function ajax(url){
req = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
req.onreadystatechange = processReqChange; //Once the state changed,the function "processReqChange" will be excuted.
req.open("GET", url, true);
req.send();
}
}
/*Wait for the response*/
function processReqChange()
{
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
//Here is your bussiness code
procBusiness();
} else {
alert("获得数据遇到问题!\n请保证您的网络连接畅通;否则,请及时与管理员联系,谢谢!:\n" + req.statusText);
}
}
}
/*
Read the XML file and retrive the data */
function procBusiness(){
var xmlResult = req.responseXML;
var root = xmlResult.documentElement;
//TO DO
}