介绍三种上传方式:
真正的异步上传,FormData的更多操作,请点击 这里
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <title></title> 6 </head> 7 <body> 8 <input type="file" id="FileData" /> 9 <br /> 10 <input type="button" id="btn1" value="上传" /> 11 <script> 12 btn1.onclick = function () { 13 var formData = new FormData(); 14 formData.append("FileData", FileData.files[0]); 15 var request = new XMLHttpRequest(); 16 request.open("POST", "Handler1.ashx"); 17 request.onload = function (e) { 18 if (request.status == 200) { 19 var res = e.target.responseText; 20 } 21 }; 22 request.send(formData); 23 }; 24 </script> 25 </body> 26 </html>
后端代码,跟 文件上传一:伪刷新上传 一样。