我正在尝试通过将$ .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
。
我不明白这里出了什么问题。