在ie浏览器中测试.代码如下:
<script type="text/javascript">
function ac()
{
//指定xml文件的来源地址
var Url="App_Data/indeximg.xml";
//创建XmlDom对象
var cdsales=new ActiveXObject("Microsoft.XMLDOM");
//设定XmlDom对象将采取异步调用的方式加载数据
cdsales.async=true; //异步加载
//加载xml文件
cdsales.load(Url);
cdsales.onreadystatechange= new function LoadedSales()
{
var txt="";
if(cdsales.readyState==4)
{
txt="loaded";
}
else{
txt="Loading.";
}
document.write(txt);
}
}
</script> <input id="Button1" type="button" value="button" onclick="ac()" />点击按钮后,一直显示的是"Loading",为什么不能加载xml?谢谢指教!
<script type="text/javascript">
function ac()
{
//指定xml文件的来源地址
var Url="App_Data/indeximg.xml";
//创建XmlDom对象
var cdsales=new ActiveXObject("Microsoft.XMLDOM");
//设定XmlDom对象将采取异步调用的方式加载数据
cdsales.async=true; //异步加载
//加载xml文件
cdsales.load(Url);
cdsales.onreadystatechange= new function LoadedSales()
{
var txt="";
if(cdsales.readyState==4)
{
txt="loaded";
}
else{
txt="Loading.";
}
document.write(txt);
}
}
</script> <input id="Button1" type="button" value="button" onclick="ac()" />点击按钮后,一直显示的是"Loading",为什么不能加载xml?谢谢指教!
{ if(cdsales.status==200){
txt="loaded";
}
else{
txt="Loading.";
}
}
你用这个方法试试loadXml = function(fileRoute){
xmlDoc=null;
if (window.ActiveXObject){
xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
xmlDoc.async=false;
xmlDoc.load(fileRoute);
}else if (document.implementation && document.implementation.createDocument){
var xHRO = new window.XMLHttpRequest(); // 兼容 Chrome
xHRO.open('GET',fileRoute,false);
xHRO.send(null);
xmlDoc = xHRO.responseXML;
}else{
xmlDoc=null;
}
return xmlDoc;
}
{
var txt="";
if(cdsales.readyState==4)
{
txt="loaded";
}
else{
txt="Loading.";
}
//document.write(txt); ///不要在函数中使用此语句,会导致当前页面的内容会被覆盖,改用append方法
document.body.appendChild(document.createTextNode(txt));
}