1 <div class="imgDIv"> 2 <label>上傳pdf</label> 3 <input id="fileId" type="file" accept="application/pdf" class="imgPic"/> 4 </div> 1 var formData = new ...
1 <div class="imgDIv"> 2 <label>上傳pdf</label> 3 <input id="fileId" type="file" accept="application/pdf" class="imgPic"/> 4 </div>
1 var formData = new FormData(); 2 var file = $("#fileId")[0].files[0]; 3 formData.append('file', file); 4 $.ajax({ 5 type:'POST', 6 url:Feng.ctxPath + "/catalog/add", 7 data:formData, 8 dataType: "formData", 9 cache: false, 10 contentType: false, 11 processData:false, 12 mimeType:"multipart/form-data", 13 success:function(data){ 14 if(data.code==200){ 15 layer.msg("保存成功!"); 16 window.parent.Catalog.table.refresh(); 17 }else{ 18 layer.msg(data.msg) 19 } 20 } 21 });
以上標紅的地方是容易犯錯的地方,這些的方是不可以少的,寫此博客,提示自己,也幫助一下有需要的朋友