上傳圖片400解決辦法


<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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM