HTML modified jQuery listener

422
November 21, 2016, at 8:07 PM

I have created a chatbox in jQuery / MySQL and PHP. To display new messages, I refresh the #chatcontent on my page using a POST HTTP request and the $('#chatcontent').html(data) method. My problem is that the DOMSubtreeModified listener will detect a change even when there are no new messages because I refresh the content each second.

So how can I detect that there actually is a new message ?

Answer 1

The ideal setup for this type of problem would be send data from server to client using websockets. Just listen for the new messages on server and send it to the client using websocket.

If you do not want to use websocket, do a AJAX polling lets say every 3 seconds and pass the ID of last received message. Update the innerHTML of DIV only if you have received some JSON data. Try not sending HTML content from the server.

Rent Charter Buses Company
READ ALSO
jQuery disable, and enable bxslider on window resize

jQuery disable, and enable bxslider on window resize

I've got some problem with bxslider. [nnn]I want to disable it when user resize the window under 1051px and enable again when user resize over 1051px.

565
Bootstrap Modal not working in Chrome or FireFox

Bootstrap Modal not working in Chrome or FireFox

I have a Modal Popup window that brings up images on my website. Everything works great in Microsoft Edge Browser, however, when I go to FireFox or Chrome, the Modal pops up, but doesn't show up solid and you can see through it to the background.

781
Parallax only works on page refresh, not on redirect

Parallax only works on page refresh, not on redirect

I am using the Materialize css parallax. It works fine on the first page load up, but when it is redirected to any other page in the site, none of the parallaxes render the pictures.

322
Renderblock JS and CSS Issue - W3 Total cache plugin

Renderblock JS and CSS Issue - W3 Total cache plugin

I'm using W3 Total Cache plugin on WP 4. 3.

326