i was just looking for basic tutorial for js , this is the code i have to read file from a txt file .
<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>
this is in head of a php file and note.txt in same directory , so i expect to get an alert but dont get any response , can someone help me with this whats wrong ?
asked Dec 11, 2015 at 13:16
Sikander
2,84513 gold badges56 silver badges106 bronze badges
-
put xhr.send(null); out of that functionShailendra Sharma– Shailendra Sharma2015年12月11日 13:18:58 +00:00Commented Dec 11, 2015 at 13:18
-
@ShailendraSharma God bless you :)Sikander– Sikander2015年12月11日 13:19:50 +00:00Commented Dec 11, 2015 at 13:19
1 Answer 1
xhr.onreadystatechange= function (){
if(xhr.readyState===4){
alert(xhr.responseText);
}
xhr.send(null);
}
you are calling send() in the handler for onreadystatechange.
answered Dec 11, 2015 at 13:18
Ramanlfc
8,3541 gold badge21 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js