javascript - Show live data in browser without refresh -
i have looked around web including stack overflow's 'question , answer' history, can't find related answer mine; maybe because don't understand posts published in english beginner in programming, need explanation , think should clear , easy understand.
my question is, there easy way make php , javascript answer question:
i have 2 computers online, 1 computer opens 'my website' there scrolling news @ top of website. other computer in hand, here inside admin area.
now, add new data in 'news table db' in admin area, type it, , push click.
then @ other computer, want new data there without touching part of keyboard.
that's all, simple question maybe. it's easy facebook's developers, not me. need detailed explanation know this. know little of pdo, less js.
method 1: create log table records inserted, have javascript make requests script implements long polling:
$time=(isset($_get['timestamp']) ? $_get['timestamp'] : time()); while(true){ if($data=get_new_data($time)){ echo $data; exit; } sleep(5); }
method 2: use web sockets push data clients inserted extending method above send websocket message, set $time time(), , sleep instead of exit. https://developer.mozilla.org/en-us/docs/web/api/websockets_api
Comments
Post a Comment