jquery - Ajax Long Polling -
jquery - Ajax Long Polling -
i asked question on stackoverflow function of mine , people recommended utilize ajax long polling. have spent past couple of days researching subject , have tried write basic long polling code, none of has worked , can not work @ all.
here basic function:
<script language='javascript' type='text/javascript'> var interval=self.setinterval("checkformessages()",4000) function checkformessages() { $('#incomingmessages<?php echo $otherchatuser ?>').load('checkfornewmessages.php?username=<?php echo $username; ?>&otherchatuser=<?php echo $otherchatuser; ?>'); } </script>
would able tell me how turn basic long polling function, or direct on path need there. help much appreciated. thanks!
usually (i.e. when not using long polling), javascript code create request server , server homecoming info immediately. however, server may not have of import immediately. in illustration (which seems chat), person you're chatting may not have said when create request checkfornewmessages.php
. hence when javascript client asks server has been said, server has nil respond except "nothing has been said."
with long polling instead of having checkfornewmessages.php
homecoming "nothing has been said," don't homecoming checkfornewmessages.php
until there of import homecoming with.
in other words, long polling work, interesting stuff done on server side in checkfornewmessages.php
page. javascript code doesn't have except contact checkfornewmessages.php
, wait respond.
jquery ajax long-polling
Comments
Post a Comment