javascript在load(.xml)时加载出错 javascriptxmlload()dreamveaver网页前端 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 xmlDoc=document.implementation.createDocument('', '', null);xmlDoc.async=falsealert("即将加载文件"+xmlDoc); xmlDoc.load('canshu.xml'); 因为你异步加载,导致还未加载xml文件完毕就执行到console.log("根节点标签"+xmlDoc.firstChild.tagName)这句了 参考: XML Parser这样是不是更兼容?function loadXmlDoc(){ var zhishuArray=new Array(); var xmlDoc; alert("进入loadXmlDoc"); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.status==200) { xmlDoc=xmlhttp.responseXML; alert("加载文件之后"+xmlDoc); console.log("根节点标签"+xmlDoc.firstChild.tagName); alert("根节点标签"+xmlDoc.firstChild.tagName); getmessage(); } else { alert('加载失败,状态码: '+xmlhttp.status); } } alert("即将加载文件"+xmlDoc); xmlhttp.open("GET","canshu.xml",false); xmlhttp.send();} window.open求助 请教 JS如何调用其它网站的页面? 網頁如何防止復制? 请教JS中document.getElementById(nowClickId).style.backgroundColor中问题 图片滚动终极问题:100分酬谢,在线等! “下移”按钮 问showModalDialog的问题 【求解】jQuery如何判断大于一屏和小于一屏 javascript的这段代码看不懂,myFunction()和forEach() js调用百度地图API,由于异步执行导致结果顺序不对以及数据丢失 JS返回上一级页面, 显示用户名
xmlDoc.async=false
alert("即将加载文件"+xmlDoc);
xmlDoc.load('canshu.xml');
因为你异步加载,导致还未加载xml文件完毕就执行到console.log("根节点标签"+xmlDoc.firstChild.tagName)这句了
这样是不是更兼容?function loadXmlDoc(){
var zhishuArray=new Array();
var xmlDoc;
alert("进入loadXmlDoc");
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.status==200)
{
xmlDoc=xmlhttp.responseXML;
alert("加载文件之后"+xmlDoc);
console.log("根节点标签"+xmlDoc.firstChild.tagName);
alert("根节点标签"+xmlDoc.firstChild.tagName);
getmessage();
}
else
{
alert('加载失败,状态码: '+xmlhttp.status);
}
}
alert("即将加载文件"+xmlDoc);
xmlhttp.open("GET","canshu.xml",false);
xmlhttp.send();
}