html5 ajax 文件上传
http://html5demos.com/dnd-upload
看这个例子看了一会儿...这个是支持拖拽的上传。
下面代码是一个简单的ajax的文件上传:
1 function match(url,rs) 2 { 3 var formData = new FormData(); 4 var room_type = $("#room_type option:selected").val(); 5 //文件,注意这里得有个 .get(0) 6 var file = $("#fileInput").get(0).files[0]; 7 if( room_type == "" || file == null ) 8 { 9 alert("请填写完善信息"); 10 return; 11 } 12 13 formData.append('room_type',room_type); 14 formData.append('file',file); 15 16 var xhr = new XMLHttpRequest(); 17 xhr.open('POST', url); 18 xhr.onload = function() { 19 $(rs).html("上传完成"+ this.response); 20 }; 21 22 xhr.upload.onprogress = function (event) { 23 $(rs).html("正在上传中..."); 24 } 25 26 xhr.send(formData); 27 }