2 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊
你不能FormData在另一個(gè)對(duì)象中發(fā)送一個(gè)對(duì)象。所有 POST 參數(shù)都必須在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貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
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 關(guān)注
- 154 瀏覽
添加回答
舉報(bào)