Answer the question
In order to leave comments, you need to log in
Why does ajax upload send multiple files?
I downloaded a plugin for ajax file upload, this one: https://github.com/burt202/lite-uploader/blob/mast... I inserted
the following code on the page:
$('.fileUpload').live('click', function(){
$(this).liteUploader({
script: '/upload_images/'
})
.on('lu:progress', function (e, percentage) {
$(this).parent().find('.upimtx .progressbar').css('width', percentage + '%');
})
.on('lu:success', function (e, response) {
alert(response);
obj = jQuery.parseJSON(response);
$(this).parent().find("img").remove();
$(this).parent().find(".images_hidden").val(obj.imagename);
$(this).parent().prepend(obj.image);
});
});
Answer the question
In order to leave comments, you need to log in
For starters, forget about live('click'), on() has been used for a long time.
You initialize the uploader every time, why?
Why the whole live click wrapper, instead of $('.file').liteUploader()
I don't know, it's probably a crutch, but that's how it turned out for me
function in_upload(box){ // инициализация для загрузки через ajax
$(box).liteUploader({
script: '/upload_images/'
})
.on('lu:progress', function (e, percentage) {
$(this).parent().find('.upimtx .progressbar').css('width', percentage + '%');
})
.on('lu:success', function (e, response) {
obj = jQuery.parseJSON(response);
$(this).parent().find("img").remove();
$(this).parent().find(".images_hidden").val(obj.imagename);
$(this).parent().prepend(obj.image);
});
}
in_upload('#fileUpload_' + index); // вызываем функцию инициализации
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question