html5 xmlhttprequest 图片异步上传
2016-06-23来源:

<!doctype html>

<html>

<head>

<meta charset=utf-8/>

<tilte>uploadfile</title>

<script>

function uploadfile(){

var formdata = new formdata();

var files = document.getelementbyid('file').files;

var file = files[0];

formdata.append('file',file);

var xhr = new xmlhttprequest();

xhr.open('post','index.html',true);

xhr.onload = function(e){

if(this.status == 200){

document.getelementbyid(resulte).innerhtml = this.response;

}

};

xhr.send(formdata);

}

</script>

</head>

<body>

<form id=form1 enctype=multipart/form-data>

<input type=file id=file name=file><br/>

<input type=button value=upload onclick=uploadfile();>

</form>

<output id=result></output>

</body>

</html>

推荐信息
Baidu
map