上传图片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>
posted @ 2020-08-06 17:05  碧果果  阅读(1156)  评论(0编辑  收藏  举报