[英]Javascript : unable to read file content using XMLHttpRequest
我只是在尋找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);
}
您正在處理程序中為onreadystatechange
調用send()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.