2 回答
TA贡献1831条经验 获得超10个赞
你不能FormData在另一个对象中发送一个对象。所有 POST 参数都必须在form_data.
function addPatient() {
if ($("#frmcompany").valid()) {
var url = '';
var data = '';
var method = '';
var form_data = new FormData(document.getElementById("frmcompany"));
var upload_date = $('#file').prop('files')[0];
form_data.append('file', upload_date);
if (isNew == true) {
url = 'php/add_patient.php';
data = $('#frmcompany').serialize();
method = 'POST';
}
$.ajax({
type: method,
url: url,
dataType: 'JSON',
cache: false,
contentType: false,
processData: false,
data: form_data,
success: function(data) {
if (isNew == true) {
alert("Company Addedd");
}
}
});
}
}
TA贡献1825条经验 获得超4个赞
function addPatient()
{
var upload_date = $('#file').prop('files')[0];
var form_data = new FormData();
form_data.append('file', upload_date);
$.ajax({
url: 'php/add_patient.php',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'POST',
success: function(response) {
console.log(response);
},
error: function(error) {
console.log(error);
}
});
}
- 2 回答
- 0 关注
- 128 浏览
添加回答
举报