請教大家
在使用google chrome / firefox /ie9以上版本開下列網頁時,會出現錯誤訊息
Uncaught TypeError:xmldoc.load is not a function
Failed to load resource: the server responed with a status 404 (not found)
要如何寫成讓他可以支援新版的瀏覽器呢?謝謝
function GetXmlFile(url){
var xmldoc = null;
documentLoaded = 0;
window.status = url;
// NS6+
if (document.implementation && document.implementation.createDocument) {
xmldoc = document.implementation.createDocument("", "", null);
xmldoc.addEventListener("load", function() { xmlHandler(xmldoc); }, false);
} else if (window.ActiveXObject) {
// IE 5+
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.onreadystatechange = function() { if (xmldoc.readyState == 4) xmlHandler(xmldoc); }
} else {
alert('Your Browser does not support XML import methods, you menu may not work correctly');
}
if (xmldoc != null) {
var xhr = new XMLHttpRequest;
xhr.open('get',url",true);
以下這段試試
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(file);
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.async=false;
xmlDoc.load(file);
}
catch(e)
{
try //Google Chrome
{
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",file,false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML.documentElement;
}
catch(e)
{
error=e.message;
}
}
}