当我使用Ajax提交时我无法获取我的FormData ..Form提交没有FormData ..我想我错过了一些东西..但是不能得到它..请帮助我。 我的代码............................................... < / p>
<form id="regfrm" name="regfrm" class="form-horizontal" method="POST" action="<?php echo site_url('settings/finance'); ?>">
<div class="form-group row">
<label for="txt_sqdcp" class="col-sm-2 col-form-label">Select File to Upload</label>
<div class="col-sm-10">
<div class="input-group">
<span class="btn btn-file btn-info" title="">
<span class="fileupload-new">Click here to choose file</span>
<span class="fileupload-exists">Change</span>
<input type="file" name="userfile" id="userfile" />
</span>
<div style="padding-top: 6px;">
<span id="vop_fileName"></span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="txt_sqdcp" class="col-sm-2 col-form-label">Excel Sheet Name</label>
<div class="col-sm-10">
<div class="input-group">
<input class="form-control" type="text" id="txt_excel" name="txt_excel" value="" required="required"> Eg : VOP Feb 17
<!-- <div class="loadingGIF" id="vop_loader"><img src="<?php // echo base_url(); ?>assets/logo/loading.gif" /></div> -->
<span id="excelcheck" class="text-yellow"></span>
</div>
</div>
</div>
<div class="form-group row pull-right">
<input type="hidden" name="txt_id" id="txt_id" value="<?php if(!empty($edit_sqdcp)) echo @$cat; ?>" />
<input type="submit" id="sub" name="sub" class="btn <?php if(empty($edit_sqdcp)) echo "btn-success"; else echo "btn-warning";?>" value="<?php if(empty($edit_sqdcp)) echo "submit"; else echo"update";?>"/>
</div>
<?php // echo form_close(); ?>
</form>
脚本
$("#regfrm").submit(function(e){
var formObj = $(this);
var formURL = formObj.attr("action");
var formData = new FormData(this);
console.log(formData);
$.ajax({
url: formURL,
type: 'POST',
data: formData,
mimeType:"multipart/form-data",
contentType: false,
cache: false,
processData:false,
success: function(data, textStatus, jqXHR)
{
},
error: function(jqXHR, textStatus, errorThrown)
{
}
});
});