ajax for notification

1

To change the html whenever an information in the bank is changed without refresh (style notifications of facebook) is done like? I am currently using a timer, I was wondering if there is a better way to do the request only when needed

[I'm doing this: setInterval ("ajax ()", 60000);]

    
asked by anonymous 07.11.2017 / 15:02

1 answer

1

There are several techniques for keeping information up-to-date with the server. This one you're doing is one of them, and it's perfectly acceptable.

There are other more up-to-date forms, but they have certain browser limitations. One of these is WebSockets .

The way you're doing, you keep asking the server for information at a regular interval of time. This gives the impression that the application is real-time . However, your requests are made every 60 seconds. What if an information changes in the bank right after the last request? It will only be refreshed after several seconds. WebSockets maintains an open connection between the server and the client, so the server can check for new information for itself, and send it to the client when it needs it. The customer will be ready to receive this information, and update it in the DOM, or wherever.

    
07.11.2017 / 15:12