Ajax + PHP. Загрузка файла
прошу помощи. Использую такой вот код
function formSubmit(form, input) {
$.ajax({ // create an AJAX call...
data: $(form).serialize(), // get the form data
type: $(form).attr('method'), // GET or POST
url: $(form).attr('action'), // the file to call
beforeSend: function(response) {
$('#' + $(form).attr('name') + $(form).attr('id') + 'Result').html('<img id="loading-image" width=40px src="img/ajax-loader.svg" />'); // Loader https://loading.io/
$("#loading-image").show();
},
success: function (response) { // on success..
$('#' + $(form).attr('name') + $(form).attr('id') + 'Result').html(response); // update the DIV
}
});
}
<form name="form" id="1" action="ajax.php" method="POST">
<input id="uploadFile" type="file" name="uploadFile" />
<input class="button" name="add" value="Добавить" type="button" onclick="formSubmit(this.form)">
</form>
<div id="form1Result"></div>
Скажите, пожалуйста, как его модифицировать, чтобы можно было загружать файл на сервер?
Главная задача - не сломать работу этого скрипта, так как он используется во многих местах.
Спасибо!