FormDate 单独 上传图片不提交表单

var file = $("#file").get(0).files[0];//根据id获取input [type=file]的jq对象;get(0)获取js对象.通过属性files获取文件;

var formdata = new FormData();

formdata.append("file",file);

$.ajax({
    url:'/merchant/productManager/checkImageWidthAndHeight',
    type:'post',
    data:formData,
    async:false,
    cache:false,
    contentType: false, //不设置内容类型
    processData: false, //不处理数据
    success:function(data){
        if(data.success){

        }else{
            alert(data.message);
            return false;
        }
    }

});


posted @ 2023-03-29 11:45  搬砖的孟达  阅读(12)  评论(0)    收藏  举报  来源