jq使用fromDate上传图片

function updateImg(event, id) {
    var formData = new FormData();
    formData.append("file", event.target.files[0]);
    // console.log(document.getElementById('file1').files[0]);
    $.ajax({
        url: '/openapi/common/upload',
        type: 'POST',
        data: formData, // 上传formdata封装的数据包
        dataType: 'JSON',
        cache: false, // 不缓存
        processData: false, // jQuery不要去处理发送的数据
        contentType: false, // jQuery不要去设置Content-Type请求头
        success: function (res) { // 成功回调
            if (res.code == 20000) {
                alert('https://' + location.host + res.data.filePath);
                console.log($(id).find('img')[0]);
                $(id).removeClass('layui-hide').find('img').attr('src', 'https://' + location.host + res.data.filePath);
                // upImagePath = res.data.filePath;
            }
        }
    });
}

猜你喜欢

转载自www.cnblogs.com/liangziaha/p/12736107.html