使用Ajax的get方式获取服务器中txt文件内的文字内容

 

<div class="cont"></div>
    <script>
        var ajx = new XMLHttpRequest()
        ajx.open("get","./info.txt",true)
        ajx.onreadystatechange = function(){
            if(ajx.readyState!=4){
                return;
            }
            if(ajx.status>=200 && ajx.status<300){
                document.querySelector('.cont').innerHTML = ajx.responseText
            }
        }
        ajx.send()
    
    
    </script>

 

posted @ 2019-09-18 17:18  wangbing111  阅读(1582)  评论(0编辑  收藏  举报