Я пытаюсь отправить запрос по почте с помощью вызова JQuery Ajax, но на всю жизнь я не могу получить событие успеха или ошибки.Почтовый запрос отправляет файл на сервер.
Я точно знаю, что файл успешно загружен, поскольку я вижу его в журналах бэкэнда.Когда я добавляю операторы журнала консоли в части успеха / ошибки, я не получаю никаких журналов сортировки.
Вот HTML-код формы.
$(document).ready(function() {
$("#submitButton").click(function () {
console.log("sdasd");
console.log($("#my_file").val());
});
$("#reset_button").click(function () {
$("#my_file").val("");
});
$('#submit_button').on('click', function() {
$.ajax({
// Your server script to process the upload
url: 'http://127.0.0.1:5000/uploadTest',
type: 'POST',
datatype: "json",
// Form data
data: new FormData($('form')[0]),
success: function( data ) {
alert("Test Upload Successful");
},
error: function(xhr, status, error) {
alert("Test Upload Successful");
},
// Tell jQuery not to process data or worry about content-type
// You *must* include these options!
cache: false,
contentType: false,
processData: false
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="POST" action="#" enctype="multipart/form-data">
<!-- COMPONENT START -->
<div class="form-group">
<div class="input-group input-file">
<input type="file" name="file" id="my_file">
</div>
</div>
<!-- COMPONENT END -->
<div class="form-group">
<button id="submit_button" type="submit" class="btn btn-primary pull-right">Submit</button>
<button type="reset" class="btn btn-danger">Reset</button>
</div>
<p>The test must be a .docx file in the specified format </p>
<p id="file_upload_message"/>
</form>