A message appears while not displaying the results of the database

2

Colleagues,

Unfortunately I do not have any code for this doubt, as I do not know much about jquery, but I have a page where I bring the results of a mysql database, but in some cases the result takes a while to appear. How would I make a message appear (please wait, data being processed) or loading gif so the results do not appear?

I'm bringing the results as follows:

View-users.php page

<html>
.....
<h2>Relação dos usuários cadastrados</h2>
<?php echo $metodos->visualizarUsuarios(); ?>
.....
</html>

In $ methods-> ViewUsers () I bring the results of a query procedurally using mysqli _ ().

public function visualizarUsuarios(){
 ....
  $sqlVisualizar = mysqli_query($this->conexao,"SELECT * FROM visualizar_usuarios");

  while($jmVisualizar = mysqli_fetch_object($sqlVisualizar)){
    // Resultados  
  }  

}
    
asked by anonymous 30.03.2017 / 15:31

1 answer

3

All you have to do is display the message before going to the database and then you hide the message when you return the data (success or error response), example below is via ajax. Post as you are making these requisitions in the bank so that I can help you better.

function processar(){
  $('#aguarde').show();
  $.ajax( 'https://httpbin.org/delay/2' )
    .done(function() {
      alert('Terminou o processamento');
      $('#aguarde').hide();
    })
    .fail(function() {
      alert('Terminou o processamento - ERRO');
      $('#aguarde').hide();
    });
  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script><buttononclick="processar()">Processar</button>
<div id="aguarde" style="display:none">Aguarde, estamos processando</div>
    
30.03.2017 / 15:47