when user1 select user2 from list of users those who are currently online, and sends message to users2.
The user1 sent message will be saved in database through ajax.
Currently I am making ajax call using setInterval method to get messages from database for every 5 seconds. Even though if user2 not have new message, ajax request continuously goes to server for every 5 seconds. This is increases server load.
Is there any way to to update message to user2 only if user2 get’s the message, this reduce number request sent to the server.