2014-10-06 55 views
-2

我在本地系統(不在服務器上)中有一個xml文件。我想用javascript來解析它,我該怎麼做?我試着給出本地文件的位置。訪問本地系統中的xml文件

if (window.XMLHttpRequest) 
    { 
     xmlhttp=new XMLHttpRequest(); 
    } 

xmlhttp.open("GET","C:\Users\amit.m2\Desktop\metrics.xml",false); 
xmlhttp.send(); 
xmlDoc=xmlhttp.responseXML; 
+0

@quentin我知道同樣的問題已經被問,但答案是抽象的,並沒有幫我解決我的問題。期待解決這個問題的詳細過程,因爲我是JavaScript xml和ajax的新手。 – Amit 2014-10-06 09:46:38

+0

重複問題的答案並不是一點抽象的。 – Quentin 2014-10-06 09:53:11

+0

@如果你覺得有詳細的答案可用,請與我分享。 – Amit 2014-10-06 10:01:59

回答

-1
$.ajax({ 
      url: 'input.xml', // Name of the file in the local 
      dataType: "xml", // input file type 
      success: parse, // Call the parse function on success`enter code here` response 
    error: 
     function(){ 
      alert("Unable to load or something is Wrong !!!"); 
     } 
     }); 

     function parse(document){ 
     $(document).find("Inputdata").each(function(){ 
     // Business logic goes here 
     }); 
    } 
+0

這是什麼?看起來你已經抓住了一大堆適合你的代碼,卻沒有試圖理解爲什麼OP代碼不適合他們(所以它可以通過消除錯誤來解決問題,或者它可能不是因爲問題可能是與代碼無關(例如同源策略)(在這種情況下,它不會))。無論哪種方式,它完全缺乏任何解釋和讀取像一個點差異的遊戲,而不是一個答案。 – Quentin 2014-10-06 09:38:35