<input type="file" id ="file" />
<script>
// 普通上传文件
$("#file").bind("change",function(){
//获取文件
var fileObj = document.getElementById("file").files[0];
var form = new FormData();
form.append("user_avatar", fileObj); // 文件对象
var xhr = new XMLHttpRequest();
xhr.open("post",api_url + 'user/avatar', true);
xhr.send(form);
xhr.onreadystatechange = function (){
if(xhr.readyState == 4 && xhr.status == 200){
console.log(xhr.responseText);
var res = eval(xhr.responseText);
console.log(res);
$avatar = $("<li />",{class:"weui_uploader_file",style:"background-image:url(/"+res[0]+")"});
console.log($avatar);
$weui_uploader_files.append($avatar);
}
}
});
</script>