iT邦幫忙

0

script應用問題

  • 分享至 

  • xImage

請教大家
在使用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);
froce iT邦大師 1 級 ‧ 2019-05-09 08:04:59 檢舉
應該不是這段的問題。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1

以下這段試試

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;  
  }  
 }  
}  

我要發表回答

立即登入回答