Request in real time with ajax

1

I need to update some information in real time, I did some research here on stackoverflow and found a very good post but I could not make it work. The posting explained the following:

Ajax notifies you if there is a change or not, if the change is detected only then make the request to update the new content:

1st Option:

var auto_atualiza = setInterval(function () {
  $.get('possui_alteracao.php', function(data) {
    if (data.possui) {
      $('#meudiv').load('listadados.php');
    }
  });
}, 30000);

2nd Option:

var cachedDOM = $('#meudiv').html();
var auto_atualiza = setInterval(function () {
  $.get('listadados.php', function(data) {
    if(data != cachedDOM) {
      $('#meudiv').html(data);
      cachedDOM = $('#meudiv').html();
    }
  });
}, 30000);

Questions

Is the script correct? How is the code in php for options 1 and 2?

Thank you.

    
asked by anonymous 08.11.2016 / 23:28

0 answers