PHP前端点击上传表格到后端读取,首次点击有效果,二次点击后不进入后端接口
<a href="#" id="fileUpload" class="am-btn am-btn-success"><span class="am-icon-cloud-download"></span> 导入数据</a>
<form id="fileForm" action="<?= $label->url('Ticket-material-importMaterial'); ?>" method="post" enctype="multipart/form-data">
<input type="file" name="file" style="display:none;" onchange="uploadFile(this)">
</form>
// 引用
document.getElementById('fileUpload').onclick = function(e) {
console.log("000000")
e.preventDefault();
document.getElementById('fileForm').querySelector('input[type=file]').click();
console.log("DIANJI")
};
function uploadFile(input) {
console.log("aaaaa")
var file = input.files[0];
var formData = new FormData();
console.log(file)
formData.append('file', file);
/* $.ajax({
url: '?g=Ticket&m=material&a=importMaterial',
type: 'POST',
data: formData,
success: function(response){
console.log(response);
}
});*/
fetch('?g=Ticket&m=material&a=importMaterial', {
method: 'POST',
body: formData
})
}