php - Is there any other way to refresh div to all members without timer? -
i have chat script made scratch. works fine, have fell site getting many requests timer. can see when inspect element on google chrome (network), timer calling function every single second. need that, make chat update members, want make other way if it's possible.
function chat_send(){ $("[data-toggle='popover']").popover('hide'); var value=$.trim($("#message").val()); //if input empty if(value.length>0){ $.ajax({ type: 'post', url: 'load.php?chat_send', data: "message=" + $('#message').val(), }); $('#message').val(''); $('#message').attr("disabled", "true"); $('#mybutton').attr("disabled", "true"); settimeout(enableme, 1000); $("#chatbox").animate({ scrolltop: $(this).height() }, "fast"); return false; } } function chat_refresh(){ $("#chatbox").animate({ scrolltop: $(this).height() }, "fast"); return false; <?php // set status 0 $sql_chat = "update users set status='0'"; $stmt_chat = $handler->prepare($sql_chat); $stmt_chat->execute(); ?> } setinterval('test()', 1000); function test(){ $('#chatbox').load('load.php?chat_refresh'); $("#online-users-text").load(location.href+ ' #online-users-text'); <?php $query_chat = $handler->query('select * users'); while($ch = $query_chat->fetch()){ if($ch['status'] == 1){ ?> chat_refresh(); <?php } } ?> }
you can test here monkstudio.biz/chat ,login see chat: username: demo password: demo123
Comments
Post a Comment