日期:2014-05-16 浏览次数:20394 次
<script type="text/javascript">
var xmlDoc=null;
try{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}catch(e){
try {
xmlDoc = document.implementation.createDocument("", "", null);
}catch(ee){ee.message}
}
xmlDoc.async=false;
xmlDoc.load("XML_001.xml");
var username=xmlDoc.getElementsByTagName("username")[0].childNodes[0].nodeValue;
document.write(username);
</script>
<script type="text/javascript"> var xmlDoc = null; var xml = "XML_001.xml"; if (window.ActiveXObject) { xmlDoc = new ActiveXObject('Microsoft.XMLDOM'); xmlDoc.async = false; xmlDoc.load(xml); } else if (document.implementation && document.implementation.createDocument) { try{ xmlDoc = document.implementation.createDocument('', '', null); xmlDoc.async = false; xmlDoc.load(xml); } catch(e){ var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("GET",xml,false); xmlhttp.send(null); xmlDoc = xmlhttp.responseXML.documentElement; } } var username=xmlDoc.getElementsByTagName("username")[0].childNodes[0].nodeValue; </script>
------解决方案--------------------
function loadXML(url) { var xmlhttp; if( window.XMLHttpRequest ) xmlhttp = new XMLHttpRequest(); else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open('GET', url); xmlhttp.onreadystatechange = function(){ if( xmlhttp.readyState==4 && xmlhttp.status==200 ){ return xmlhttp.responseXML; } } xmlhttp.send(); }