非常不多說,直接給大家上乾貨,寫的不好還請見諒。
具體代碼如下所示:
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width" /><script src="~/Scripts/jquery-1.8.2.min.js"></script><title>Index</title><script>$(function() {$(':button').click(function () {var formData = new FormData();var file = $("input[type='file']")[0].files[0];formData.append("files", file);$.ajax({url: '/Upload/Upload', //server script to process datatype: 'POST',//Ajax事件//beforeSend: beforeSendHandler,//success: completeHandler,//error: errorHandler,// Form資料data: formData,//Options to tell JQuery not to process data or worry about content-typecache: false,contentType: false,processData: false});});});</script></head><body><form enctype="multipart/form-data"><input name="file" type="file" multiple="multiple" /><input type="button" value="Upload" /><input type="text" name="userName" value="ice" /></form></body></html>
以上代碼是小編給大家分享的Ajax非同步上傳檔案執行個體代碼,希望對大家有所協助,如果大家有疑問歡迎給我留言,小編會及時回複大家的,在此也非常感謝大家對雲棲社區網站的支援!