我正在开发销售应用程序。我的弹出窗体包含交易金额,合同编号和作为文件附件的合同副本的输入。我正在使用AJAX将表单提交到操作页面。在操作页面上,我从表单中接收除文件之外的所有值。
如何通过AJAX接收文件上传?
var file = document.getElementById("file_attach");
var form_data = file.files[0];
var form_data += $('#deal_frm_brief').serialize();
$.ajax({
type: 'POST',
url: '../followup_action.php',
processData: false,
contentType: false,
data: form_data,
success: function(response) {
$('#contract_number_popup').hide();
$('#deal_content_popup').html(response);
}
});
<form role="form" name="deal_frm_brief" id="deal_frm_brief" enctype="multipart/form-data" \>
<div class="form-group" id="deal_content_popup">
<label>Enter deal amount in numbers</label>
<input type="text" class="form-control" name="txt_brief" id="deal_txt_brf" required>
</div>
<div class="form-group" id="contract_number_popup">
<label>Enter Contract number</label>
<input type="text" class="form-control" name="txt_contract" id="contract_number" required>
</div>
<input type="file" name="cntrctattch" id="file_attach" />
</form>