Jquery Validate show gif when submit

1

I'm doing a form validation and I use Jquery Validate() but I have a problem. I indicate the code

$("#formBloqueo1").validate({
    success: function() {
         $("body").css({"overflow-y":"hidden"});
         var alto = $(window).height();
         $("body").append("<div id='pre-load-web'><div id='imagen-load'><img src='/img/loading.gif' alt=''/><h1>Realizando Validación</h1></div></div>"); 
         $("#pre-load-web").css({"height":alto+"px"}); 
         $("#imagen-load").css({"margin-top":(alto/2)-30+"px"});
         //Aqui realizo mis comprobaciones

        $("#formBloqueo1").attr('action', nuevaUrl);
        $("#formBloqueo1").attr('method', 'POST');

        $("#formBloqueo1").submit();//Hago submit

The problem is that with the code above, the pre-load-web html appears duplicated and the gif does not appear, but if this line:

$("#formBloqueo1").submit();//Hago submit

I comment it so that it does not submit, the div appears perfect and the gif also, some idea of what the problem may be?

Thanks in advance

    
asked by JuankGlezz 28.06.2016 в 13:55
source

1 answer

0

You're probably inadvertently re-invoking validation by doing .submit() within success: handler

Instead of solving the form's selector with jquery, that is, $("#formBloqueo1") , try using the selector already resolved by validate() , and instead of doing it in success: do it in submitHandler: something like that as

 $("#formBloqueo1").validate({
     submitHandler: function(form) {
       ...
       form.submit();
    
answered by 28.06.2016 / 15:54
source