1 回答
TA贡献1839条经验 获得超15个赞
尝试在 javascript 中使用FormData来正确发送数据。
像这样的东西:
$('#company-logo-form').on('submit', function(e) {
e.preventDefault();
let logo = $('#logo-test').prop('files')[0]; // Since 'files' is array.
let formData = new FormData(); // Create a new form.
formData.append('action', 'uploadCompanyLogo');
formData.append('company_logo', logo);
$.ajax({
url: ajax_url,
type: 'POST',
data: formData,
contentType: false, // No content type headers.
processData: false, // Do not process sent data.
error: function(res) {
console.log(res);
},
success: function(res) {
console.log(res);
}
});
});
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报