2016-11-03 89 views
0

從幾年前在Firefox上使用XMLHttpRequest到v39讀取本地文本文件,但Firefox從所有新版本的Firefox中禁用XHR從40到現在我想更新JavaScript的我的源代碼,把它與新版本的Firefox使用javascript在Firefox上使用imacros打開文本文件

在這裏工作是我的舊代碼:

function readTextFile(file) 
    {const XMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1"); 
     var rawFile = new XMLHttpRequest(); 
     rawFile.open("GET", file, true); 
     rawFile.onreadystatechange = function() 
     { 
      if(rawFile.readyState === 4) 
      { 
       if(rawFile.status === 200 || rawFile.status == 0) 
       {   allText = rawFile.responseText; 
         } 
      } 
     } 
     rawFile.send(null); 
     rawFile = null; 
     } 
readTextFile("file:///D:/textfile.txt"); 

任何幫助,將不勝感激

回答

0

沒有必要的複雜ISSU即剛剛嘗試像這樣:

const xhr = new Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1")(); 
xhr.open("GET", "file:///D:/textfile.txt", false); 
xhr.send(null); 
var text = xhr.response; 
// alert(text); 
+0

您sourcode很簡單,但在Firefox的全部去掉XHR並與附近的費切爾API 代替你可以更新與新的API – John

+0

劇本我不這麼去想XHR。在Firefox 47和'iMacros for Firefox'8.9.7上成功測試。如果你的意思是[取API](https://developer.mozilla.org/ru/docs/Web/API/Fetch_API),在這種情況下,它似乎沒有用處。 – Shugar

相關問題