jQuery Post表单数据文件未上传

时间:2018-12-15 15:33:25

标签: javascript jquery ajax jquery-file-upload jqueryform

我正在尝试通过将$ .post与输入字段和文件字段一起提交。

我的代码是

$('#serviceAddForm').submit(function (e) {

    var url = e.target.action ; // get the target
    var formData = new FormData($(this)[0]);
    responseGenerate(url,formData,'service-table','serviceAddForm');
})
function responseGenerate(url,formData,table,targetDiv) {
    $.post(url, formData, function (response) {
        let target ='#'+targetDiv;
        $(target+'#DetailsMessage').empty();
        $(target+' #errorMessage').empty();
        $(target+'#successMessage').text('Created successfully');
        $(target).trigger( "reset" );
        $('#'+table).DataTable().ajax.reload(null,false);
    }).fail(function(response) { 
        let target ='#'+targetDiv;
        $(target+'#successMessage').empty();
        obj = response.responseJSON;
        $(target+'#errorMessage').text(obj.message);
        $.each(obj.errors, function(i, item) {
            $(target+'#DetailsMessage').text(item);
            $(target+' #DetailsMessage').append("<br>");
        });
    })
}

现在我遇到错误TypeError: 'append' called on an object that does not implement interface FormData

我不明白这里出了什么问题。

0 个答案:

没有答案