Итак, я делаю этот код загрузки файла на jquery-step wizard.
первый wizard-шаг - это загрузка файла, но он просто читает файл и возвращает данные на втором этапе.wizard-step
<form class="form" role="form" id="read-excel" method="POST" action="{{ url('job/readexcel') }}" enctype="multipart/form-data">
@csrf<div class="form-group">
<label for="input-file-now"> File Excel </label>
<input type="file" id="fileexcel" name="fileexcel" class="dropify" required data-allowed-file-extensions="xls xlsx" />
</div>
<button class="col-md-12 btn btn-dark" type="submit">Review & Summary</button>
</form>
поэтому на 2-м шаге я хочу, чтобы файл на 1-м шаге был загружен здесь.
$('form#read-excel').submit(function (e) {
console.log('submited');
e.preventDefault();
let formData = new FormData(this);
$(`#the-body`).empty();
axios.post( READ_FILE_URL, formData, config)
.then( (response) => {
console.log(response);
$('body').loadingModal('destroy')
//for loop code
//do something..
//go to 2nd step
})
.catch( (error) => {
$('body').loadingModal('destroy')
alert('Error see log');
console.log(error);
});
$('form#upload-excel').submit( function (e) {
console.log(formData.get('fileexcel'));
e.preventDefault();
Swal({
title: 'are u sure?',
text: 'Some TnC.",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ok'
}).then((result) => {
if (result.value) {
axios.post(UPLOAD_URL, formData, config)
.then((response) => {
console.log(response);
$('body').loadingModal('destroy')
swal({
title: 'Good!',
html: 'upload success ',
type: 'success',
showCancelButton: false,
showConfirmButton: false
})
})
.catch((error) => {
$('body').loadingModal('destroy')
alert('error')
console.log(error);
});
}
})
e.stopImmediatePropagation(); // This Does the work for prevent upload double times
})
})
Так что дело обстоит так.когда я загружаю файл (например: data1.xlsx ), а затем перехожу ко второму шагу мастера и регистрирую данные FormData console.log(formData.get('fileexcel'))
.он возвращает data1.xlsx .но когда я возвращаюсь к 1-му шагу и перезагружаюсь с другим файлом (например: data2.xlsx ) и иду на 2-ю страницу и загружаем его на сервер .он возвращает data1.xlsx , а не data2.xlsx .