鉴于所有文件(html文件,文本文件等)都在网络上, 有没有什么方法可以读取文本文件并使用ActiveX旁边的textarea打印它们?除了使用ActiveX之外,有没有什么方法可以在javascript中读取文本文件?
我已经试过这样的,但它没有达到的目标:
function getSelectedItem(){ var client = new XMLHttpRequest(); if(document.codeForm.dropList.value == "foo") client.open('GET', 'foo.txt'); else if(document.codeForm.dropList.value == "bar") client.open('GET', 'bar.txt'); client.onreadystatechange = function() { //This actually displays the message in the file alert(client.responseText); //But this doesn't. This just displays "undefined" // document.codeForm.source.value = client.reponseText; } client.send(); }
因为我实际上可以显示与文件上下文警报消息,我相信会有一些方法来做到这一点。 (实际上文件的内容似乎进入“client.reponseText”, ,但它的数据类型是DOMstring,不只是字符串。)
任何意见将不胜感激。 谢谢。
这完美的作品!谢谢! – devEvan 2011-04-13 04:33:06
@Mike Ruhlin-wat如果txt和html文件都存在于系统本地 – Varun 2011-09-29 06:51:28