Get server response without using setinterval for chat applaton php jquery

I made a chat application, here is the update code

setInterval(function() { $('#DisplauDiv').load('show-chat.php?session=<?php echo $_GET['session'];?>'); }, 1000); 

And this will continue every second, which will slow down my Mysql. Although I tickle Facebook (firebug), they have nothing like this to get a response from the server.

Tell me how to do it.

Thanks in advance for reading and reproducing this.

+4
source share
1 answer

well setInterval bad man comit take a look at comet

also see this answer Reverse Ajax implementation using php

also see this link How did facebook chat windows appear?

Open firebug, you will be on facebook page, open the network panel in firebug and go to xhr, you will notice a continuous spinning wheel, which is COMET ...

+1
source

Source: https://habr.com/ru/post/1369129/


All Articles