Jquery - Loop a function

Asked

Viewed 118 times

0

Good evening everyone. I am learning a little Jquery and wanted a help. I have the following code:

$(document).ready(function(){
$('#btnEnviar').click(function(){
    var caminho = ("/uploads/");

    $("input[name='arquivo']").each(function() {


        $('#formUpload').ajaxForm({
            uploadProgress: function(event, position, total, percentComplete) {
                $('progress').attr('value',percentComplete);
                $('#porcentagem').html(percentComplete+'%');
            },          
            success: function(data) {
                $('progress').attr('value','100');
                $('#porcentagem').html('100%');                
                if(data.sucesso == true){
                    $('#resposta').html('<img class="photo_uploaded" src="'+caminho+''+ data.msg +'" />');
                }
                else{
                    $('#resposta').html(data.msg);
                }                
            },
            error: function(){
                $('#resposta').html('Erro ao enviar requisição!!!');
            },
            dataType: 'json',
            url: 'upload3.php',
            resetForm: true
        });
    });
});

});

I’m trying to loop the function so that each image is loaded 1 in 1. But it’s garbling everything together. Someone can help?

Sorry for any publishing error.

  • Can you explain better what you mean by "it’s carrying everything together"? How many images do you have? come from ajax?

  • Well, come on. I just put 2 input type="file" to test. The Progress toolbar are encehndo together, which indicates that it is only running once the upload and cannot, after all it is 2 input. Then it has to be the following logic: For each input, run the upload function.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.