ajax for notification

Asked

Viewed 138 times

1

To change the html whenever a information is changed in the bank without refresh (like the facebook notifications) is done as? I am currently using a timer, wanted to know if there is a better way to make the request only when necessary

[I am doing this way: setInterval("ajax()", 60000);]

  • 1

    setInterval is one way, another is for example websockets: https://answall.com/questions/19345/howto work with websockets?s=6|0.0000

1 answer

1


There are several techniques to keep information up to date with the server. This is one of them, and it is perfectly acceptable.

There are other more up-to-date ways, but they have certain limitations regarding browsers. One of them is the Websockets.

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

  • thank you very much, I will read about the Websockets, helped me basntante.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.