Home » Jquery » jquery – Update Chat for everyone when user sent a message with PHP-Exceptionshub

jquery – Update Chat for everyone when user sent a message with PHP-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have checked the all similar questions but I saw that people are recommending WebSockets. Is there any way to check if there is a new message and automatically update the chat? Is it possible without using WebSockets?

Note this code works every 10 sec but I don’t wanna overcharge the database

setInterval(function() {
  $.ajax({
    type: "post",
    url: "myurl.html",
    datatype: "html",
    success: function(data) {
      //do something with response data
    }
  });
}, 10000); //time in milliseconds
How to&Answer:

I recommend you check out this package
https://github.com/walkor/phpsocket.io