JS编程题(文件读取类)

读取服务器文件

var xhr=new XMLHttpRequest();
xhr.onreadystatuschange=function(){
if(xhr.readystate===4&&xhr.status===200)
console.log(xhr.responseText);}
xhr.open('get',url,true);
xhr.send();

读取本地文件

function readfile(id){
d=var file=document.getElementById(id).files[0];
var reader=new FileReader();
reader.readAsText(file);
reader.function(data){
console.log(data,this.result);
}

猜你喜欢

转载自blog.csdn.net/weixin_43836308/article/details/88708004