Getting information from the database without refreshing the page

3

I have a system in which it takes information from the database. And this database is getting direct data, so I wanted to know how to get this data and display it on the page, but without this page being updated.

This system is in php.

    
asked by anonymous 12.06.2014 / 16:24

2 answers

4

You'll need ajax for this, here's a minimalist example:

$.ajax({
 url:'minha_pagina_acesso_banco.php', //sua página em php que retornará os dados
 type:'POST', // método post, GET ...
 data: 'param=1&param2=2', //seus paramêtros
 success: function(data){ // sucesso de retorno executar função
  $('#result').html(data); // adiciona o resultado na div #result
 }
});

You can perform this function according to user action, in a time interval, when loading the page and etc.

For more information on using jQuery.ajax ()

    
12.06.2014 / 16:34
0

I recommend using GET in Jquery.

$.get("minha_pagina_acesso_banco.php",
function(data){
   $('#result').html(data);
});

As you can see the code gets smaller, you can send and receive data like this.

The same syntax for post, if you want to send forms, just change the method.

$.post("minha_pagina_acesso_banco.php", 
function(data){
   $('#result').html(data);
});

Check out

link
link

In order not to reload the information every time the request is made, save the date of the last update in a PHP session variable, so that you change the screen every time you make the request. just echo the screen when the include / change date is different.

$.get("minha_pagina_acesso_banco.php",
function(data){
   if(data!=''){
      $("#result").html($("#result").html()+data);
   }
});
    
15.07.2015 / 14:40