本文介绍了通过客户端javascript读取txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是javascript的新手并试图将一个txt文件打开到var然后将其注入到html div ...
我尝试使用fopen但是我没有成功。
I'm new to javascript and trying to open a txt file into var and then inject it to html div...I tried to use fopen but I didn't succeed.
<script type="text/javascript">
file = fopen(getScriptPath("info.txt"), 0);
file_length = flength(file);
var content = fread(file,file_length);
var div = document.getElementById("myDiv");
//alert(div);
div.innerHTML = "";
div.innerHTML = content;
</script>
推荐答案
废弃的问题:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","YOUR_FILE.txt",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseText;
by Freek8
by Freek8
这篇关于通过客户端javascript读取txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!