Javascript FileReader onload not firing

前端 未结 4 848
故里飘歌
故里飘歌 2020-12-31 03:02

I haven\'t used JavaScript in a while and I can\'t seem to read a text file and display the contents.

I\'ve tried onload as well as onloadend

4条回答
  •  无人及你
    2020-12-31 03:30

    you can use ajax to get the content of your file:

    var reader= new XMLHttpRequest();
    reader.open('GET', '/pi.txt');
    reader.onreadystatechange =readSuccess();
    function readSuccess(evt) {                                             
       var field = document.getElementById('main');                        
       field.innerHTML = reader.responseText;                                
    };
    reader.send();
    

提交回复
热议问题