Answer the question
In order to leave comments, you need to log in
How to handle multi-upload files?
I conjure over the module of sending files to the server. There is a desire to provide multi-boot. The field figured out how to animate, but there is not enough knowledge for jquery. Tell me how to fix the code to a working state. Thank you!
$('button[id^=\'button-upload\']').on('click', function() {
var node = this;
$('#form-upload').remove();
$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" multiple="true" (Это я уже добавил)/></form>');
$('#form-upload input[name=\'file\']').trigger('click');
$('#form-upload input[name=\'file\']').on('change', function() {
$.ajax({
url: 'index.php?route=information/contact/upload',
type: 'post',
dataType: 'json',
data: new FormData($(this).parent()[0]),
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
$(node).button('loading');
},
complete: function() {
$(node).button('reset');
},
success: function(json) {
$('.text-danger').remove();
if (json['error']) {
$(node).parent().find('input').after('<div class="text-danger">' + json['error'] + '</div>');
}
if (json['success']) {
alert(json['success']);
$(node).parent().find('.success').html(json['file']);
$(node).parent().find('input').attr('value', json['file']);
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question