//
//加载XML文件
//
var xmlDoc;
function loadXML(xmlfile){
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(xmlfile);
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load(xmlfile);
}
else
{
alert('Your browser cannot handle this script');
}
}
//
//下载通用代码
//
var xmlHttp; /*XMLHttpRequest对象 */
function createXMLHttpRequest(){
if (window.ActiveXObject){ /*在IE下初始化XMLHttpRequest对象 */
try{
//新版本的 Internet Explorer
xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
}catch (otherMicrosoft){
try {
//较老版本的 Internet Explorer
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed){
// 还是失败,那么就认为创建失败……
xmlHttp= false;
}
} else if(window.XMLHttpRequest){ /*在Firefox下初始化XMLHttpRequest对象 */
xmlHttp = new XMLHttpRequest();
}
if(!xmlHttp)
alert("创建 XMLHttpRequest 对象失败!");
}
function startRequest(doUrl){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange; /* 设置回调函数为handleStateChange. */
xmlHttp.open("GET", doUrl, true); /*通过get方法来请求目标 doUrl 并且设置为异步完成请求*/
xmlHttp.send(null);
}
function handleStateChange(){ /*XMLHttpRequest对象内部状态每次有变化时候都会调用 handleStateChange 函数。*/
if (xmlHttp.readyState == 4 ){ /*请求完成*/
if (xmlHttp.status == 200 ){ /*服务器的HTTP状态为200,既OK */
// 一切OK,调用处理过程
// DoMyXML();
}else if(XMLHttp.status == 404){
//文件不存在
alert("Requested URL is not found.");
}else if(XMLHttp.status == 403){
//没有权限
alert("Access denied.");
}else
alert("status is " + XMLHttp.status);
}
}
}
//加载XML文件
//
var xmlDoc;
function loadXML(xmlfile){
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(xmlfile);
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load(xmlfile);
}
else
{
alert('Your browser cannot handle this script');
}
}
//
//下载通用代码
//
var xmlHttp; /*XMLHttpRequest对象 */
function createXMLHttpRequest(){
if (window.ActiveXObject){ /*在IE下初始化XMLHttpRequest对象 */
try{
//新版本的 Internet Explorer
xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
}catch (otherMicrosoft){
try {
//较老版本的 Internet Explorer
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed){
// 还是失败,那么就认为创建失败……
xmlHttp= false;
}
} else if(window.XMLHttpRequest){ /*在Firefox下初始化XMLHttpRequest对象 */
xmlHttp = new XMLHttpRequest();
}
if(!xmlHttp)
alert("创建 XMLHttpRequest 对象失败!");
}
function startRequest(doUrl){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange; /* 设置回调函数为handleStateChange. */
xmlHttp.open("GET", doUrl, true); /*通过get方法来请求目标 doUrl 并且设置为异步完成请求*/
xmlHttp.send(null);
}
function handleStateChange(){ /*XMLHttpRequest对象内部状态每次有变化时候都会调用 handleStateChange 函数。*/
if (xmlHttp.readyState == 4 ){ /*请求完成*/
if (xmlHttp.status == 200 ){ /*服务器的HTTP状态为200,既OK */
// 一切OK,调用处理过程
// DoMyXML();
}else if(XMLHttp.status == 404){
//文件不存在
alert("Requested URL is not found.");
}else if(XMLHttp.status == 403){
//没有权限
alert("Access denied.");
}else
alert("status is " + XMLHttp.status);
}
}
}