BernaMariano
BernaMariano

Reputation: 866

Refresh page after a database entry without Javascript's setTimeout()

Isn't there a way where I can refresh the page right after a database new entry WITHOUT using Javascript setTimeout or setInterval?

Isn't there an AJAX function to do so? Or maybe a MySql function?

The only way is keep checking the database all the time? Doesn't it spend too much of the server?

My page will work like a Messenger.

Upvotes: 0

Views: 720

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074268

You need to understand that what happens on the server and what happens on the client are completely separated, and while the client has a straight-forward way to contact the server, the converse is not true. There's no way any MySQL function could possibly refresh the browser on the client machine.

So polling (with ajax or similar) is frequently how this is done. However, it's not the only way. There are various "Comet" techniques, and of course the new web sockets initiative.

Upvotes: 4

Related Questions