Update content only when accessing div

Asked

Viewed 28 times

0

I have a step-by-step form from which every step saved in the database the information. In the last step I bring the information saved as follows with jquery:

<script type="text/javascript">
function mostrar(){   
    $(document).ready(function(){                      
            $.ajax({               
                    type:'post', 
                    dataType: 'json',
                    url: 'atualizar.php',
                    success: function(dados){

                       for(var i=0;dados.length>i;i++){
                           $('#listar').append(dados[0]);
                           $('#listar').append(dados[i].id+'</td><td>'+dados[i].nome+'</td><td>'+dados[i].email+'</td></tr>');
                       }

                    console.log(dados);    
                    }
            });
    });   
}
setInterval(mostrar, 2000);
</script>

It is working perfectly, but in this case I am updating for 02 seconds the div and I would like to know if it is possible to update only when accessing the div in the last step. HTML is that way:

<fieldset>
    <!-- Última etapa do step-by-step -->
    <h4>Confirme seus dados:</h4>

    <div id="listar"></div>

    <form role="form" action="" method="post" id="contact-form">
    <div class="f1-buttons">
        <button type="button" class="btn btn-previous">Alterar</button>
        <button type="button" class="btn btn-primary">Finalizar</button>
    </div>
    </form>
</fieldset>
  • define "when to access div"

  • 1

    This is that project you were doing?

  • Hello Dvd. That, but there were changes in the course of the project :(

  • Hello Paulo Roberto. Actually it would be to access the last stage where the div I refer is.

2 answers

1


You can know when you are at the last step by checking whether on fieldset active there is a button with the text "Finish". This check is done in the function below:

function scroll_to_class(element_class, removed_height) {
    var scroll_to = $(element_class).offset().top - removed_height;
    if($(window).scrollTop() != scroll_to) {
        $('html, body').stop().animate({scrollTop: scroll_to}, 0);
    }
   if( $('fieldset:visible').find('button:contains("Finalizar")').length == 1){
      // última etapa. Faça o que deseja aqui
      alert("Última etapa");
   }
}
  • Perfect Dvd. Thank you so much again.

0

Ideally you create a function that identifies when you are in a form with the Focus option.

When editing, do not update.

And as for saving the data, I imagine it is better to save in session or cookie and only at the end fill the comic.

This will prevent bank memory wear from bringing you performance, always think about it.

  • I understand Dávil, but the information contained in each step is great and in case of the fall of the light or internet, the information will be saved and with that the user will not have to redo all processes, just log into the system.

Browser other questions tagged

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