2012-01-23 204 views
1

我使用下面的代码来读取本地JavaScript文件本地文本文件,但它不工作:从本地JavaScript文件中读取本地文本文件?

var txtFile = new XMLHttpRequest(); 
txtFile.open('GET', fileLocation, true); 

的错误,我得到:

XMLHttpRequest cannot load file:///C:/File.txt. Cross origin requests are only supported for HTTP. 

任何想法?

回答

0

看看这个:

var fileContent=''; 
var theLocation=''; 

function readFileViaApplet(n) { 
document.f1.t1.value='Reading in progress...'; 
document.ReadURL.readFile(theLocation); 
setTimeout("showFileContent()",100); 
} 

function showFileContent() { 
if (document.ReadURL.finished==0) { 
    setTimeout("showFileContent()",100); 
    return; 
} 
fileContent=document.ReadURL.fileContent; 
document.form1.textarea1.value=fileContent; 
}