<input type="file" id="img_file">
<button id="shangchuan" type="button">點擊上傳</button>
//上傳圖片的ajax
$("#shangchuan").click(function() { console.log(222) jQuery.ajaxFileUpload({ url: url + "appapi/fabu/uploadImage", //需要鏈接到服務器地址 type: 'POST', secureuri: false, fileElementId: "img_file", //文件選擇框的id屬性 ,//文件選擇框的id屬性 dataType: 'json', //json data: {}, // contentType: false, //不可缺 // processData: false, //不可缺 success: function(data, status) { console.log(data.data); console.log(data); console.log("666"); }, // error: function(XMLHttpRequest, textStatus, errorThrown) { // alert("上傳失敗,請檢查網絡后重試"); // } }) console.log(111) })
報錯
原因:<input type="file" id="img_file">沒有添加
name="file"
解決后代碼:
<input type="file" name="file" id="img_file">
<button id="shangchuan" type="button">點擊上傳</button>