0

I understand that you can refresh with ajax, periodically pulling, given a timer. But how do you set up a page to update only when an http request which has triggered/happened from the server side?

So you would typically do this

Periodic page Update:

// Use a named immediately-invoked function expression.
(function worker() {
  $.get('ajax/test.html', function(data) {
    // Now that we've completed the request schedule the next one.
    $('.result').html(data);
    setTimeout(worker, 5000);
  });
})();

Event Driven page Update: (only when server sends response)

Question: How would you do this? Is this possible?

stackoverflow
  • 15,804
  • 43
  • 121
  • 181

1 Answers1

0

The server has no connection to the client in-between requests. If you absolutely want the event driven request, you'd have to use a plugin. I'd go with the periodical ajax request.

miestasmia
  • 525
  • 1
  • 8
  • 21