Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
AJAX Success Return Repeating

I have a form to upload a profile icon image. Once the upload is complete on AJAX success, I grab the new image path and display the image. It works fine, however, if I used the script several times without refreshing the page, the new returned image flashes several times after its dynamically loaded. (See gif animation).

This repeat ‘flashing’ of the returned image seems to increase if I continue to used the script without a page refresh. So, I am guessing I’m doing something wrong here. Missing something to prevent the event from continuing to fire? Also, If I do encounter an error, the error alert also fires/repeats many times.

enter image description here

$('#image_icon').change(function() { 
    $('#icon_upload_form').submit();
});

$('#icon_upload_form').on('submit',(function(e) {
        
        var icon_loader = $(".icon_loader").show();
        
        e.preventDefault();
        e.stopPropagation();
    
        var formData = new FormData(this);

        $.ajax({
            type:'POST',
            url: '../process/process_icon_upload.php',
            data:formData,
            cache:false,
            contentType: false,
            processData: false,
            dataType   : "json",
            success:function(data){

                icon_loader.hide();

                if (data.error > 0) {
                    
                    alert(data.msg)
                    
                } else if (data.error == 0) {
                    $("#save_map_icon").fadeIn("fast");
                    $("#new_map_icon").css({"background-image":"url('../images_icons_tmp/"+data.filename+"')"})
                }
                
                return false;
                
            },
            error: function(data){
                alert("Error - "+JSON.stringify(data))
                console.log("error");
                console.log(data);
                return false;
            }
        });
    
    })
)
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda