ajax上传file文件
场景:使用ajax提交文件,因为以前都是用formSubmit/其他提交ajaxForm帮组JS,这次碰到的不想引用js
//上传 $("#btnUpload").on("click", function () { var data = new FormData(); var name = $('#fileUpload').val(); data.append("file", $('#fileUpload')[0].files[0]); data.append("name", name); $.ajax({ url: 'post/getAirDetailTemp.ashx', type: 'POST', async: false, data: data, processData: false, contentType: false, beforeSend: function () { console.log("正在进行,请稍候"); }, success: function (data) { debugger console.log(data); } }); });
参阅:https://blog.csdn.net/qq_34383344/article/details/121159768