javascript - Set ajax call only when the new record inserted to database -


i wants updated comment chat list page without refreshing page, thats have used ajax call list have call function every 5 seconds check whether new chat inserted or not database,

$(document).ready(function(){     setinterval(function(){         $.ajax({             type:'post',             url: baseurl+"chat",             cache: false,             data: datastring,             crossdomain: true,             success: function(data){                 var getdata = json.parse(data);                 if(getdata.status == "success")                 {                        for(i=0;i<getdata.chat.length)                     {                         $("chatlist").text("");                         $("chatlist").append("<span class='black'>"+getdata["chat"][i].name+" : <span class='blue'>"+getdata["chat"][i].comment+"</span>");                     }                 }                 else                 {                     alert(getdata.message);                 }              }         });     },5000); }); 

so wants know if there easy way or php mysql possible send page new comment inserted notification ?

you can use websocket, socket.io example. allow send notifications server client. so, when recieve data chat (cient) in api (server), after updating database, have send 'notification' client.

when client notification, can make ajax call :

socket.on('notification', function(){   doyourajaxstuff(); }); 

Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -