Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My JS:
- ======
- // jQuery Document
- $(document).ready(function(){
- //If user wants to end session
- $("#exit").click(function() {
- var exit = confirm("Are you sure you want to end the session?");
- if(exit==true){window.location = 'index.php?logout=true';}
- });
- //If user submits the form
- $("#submitmsg").click(function() {
- var clientmsg = $("#usermsg").val();
- $.post("post.php", {text: clientmsg});
- $("#usermsg").attr("value", "");
- return false;
- });
- //Load the file containing the chat log
- function loadLog(){
- var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request
- $.ajax({
- url: "log.php",
- cache: false,
- success: function(html) {
- $("#chatbox").html(html); //Insert chat log into the #chatbox div
- //Auto-scroll
- var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //Scroll height after the request
- if(newscrollHeight > oldscrollHeight){
- $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
- }
- /**
- * Here, the change starts!!!
- /**/
- },
- complete: function() {
- setTimeout(loadLog, 500);
- }
- });
- }
- loadLog();
- });
- /**
- * End of Javascript
- /**/
- I created log.php, too.
- log.php:
- ========
- <?php
- while((!file_exists("log.html") || filemtime("log.html") < (time()-4) ) && time()%20) { //Don't change the 20 to a high number. Leave some space to 30. To high numbers can cause Network-Timeout-Errors
- sleep(1);
- clearstatcache(true,"log.html");
- }
- echo file_get_contents("log.html");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement