php - How to check data from mysql realtime using ajax post requests? -
how check data mysql realtime using ajax post requests ?
i use code check in mysql , if user have new message it's echo you have new message
text on realtime.
and code post get_data.php
every 1 sec , think it's work hard server , client ,
when try it's not work, how can ?
<script type="text/javascript" src="js/jquery-1.4.1.min.js"></script> <form id="idform"/> <input name="uid" value="1234"/> </form> <div id="result_data"></div> <script type="text/javascript"> $(function(){ setinterval(function(){ $.ajax({ type: "post", url: get_data.php, data: $("#idform").serialize(), // serializes form's elements. success: function(data) { $('#result_data').show(); } }); },1000); }); </script>
your best practice go websockets. protocol overhead smaller http , play ping , pong server check new data.
with websockets client send message emitting data server receive , e.g. broadcast out other clients.
try head in socket.io did understand ;)
Comments
Post a Comment