var xmlHttp
function createXMLHttpRequest(){
if (window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
}
else if (windows.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET","innerHTML.xml",true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
document.getElementById("results").innerHTML = xmlHttp.responseText;
}
}
}
本文介绍了一种使用JavaScript中的XMLHttpRequest对象从服务器请求并处理XML文件的方法。通过定义createXMLHttpRequest函数创建XMLHttpRequest实例,并利用startRequest函数发送GET请求加载指定的XML文件。当请求状态改变时,handleStateChange函数负责将响应文本更新到页面元素中。
752

被折叠的 条评论
为什么被折叠?



