我只是在寻找js的基础教程,这是我必须从txt文件读取文件的代码。
<script type="text/javascript">
var xhr= new XMLHttpRequest();
xhr.open("GET","note.txt",false);
xhr.onreadystatechange= function (){
if(xhr.readyState===4){
alert(xhr.responseText);
}
xhr.send(null);
}
</script>
这是在同一个目录下的php文件和note.txt文件的头中,因此我希望收到警报,但没有任何响应,有人可以帮助我解决这出什么问题吗?
xhr.onreadystatechange= function (){
if(xhr.readyState===4){
alert(xhr.responseText);
}
xhr.send(null);
}
您正在呼叫send()
的处理常式onreadystatechange
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句