-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindexSChat.php
102 lines (64 loc) · 1.61 KB
/
indexSChat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
session_start();
$_SESSION['username'] = "Students";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chat Room</title>
<!-- <link rel="stylesheet" type="text/css" href="css/style.css"> -->
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
</head>
<body>
<div>
<div id = "wrapper">
<div class = "chat_wrapper">
<div id=chat>
</div>
<form method="POST" id="messageFrm">
<br><br>
<textarea name="message" cols="100" rows="2" class="textarea" class="form-control"></textarea>
</form>
</div>
</div>
</div>
<script>
LoadChat();
setInterval(function(){
LoadChat();
},100);
function LoadChat(){
$.post('handlers/messages.php?action=getMessages', function(response){
var scrollpos = $('#chat').scrollTop();
var scrollpos = parseInt(scrollpos) + 620;
var scrollHeight = $('#chat').prop('scrollHeight');
$('#chat').html(response);
if( scrollpos < scrollHeight){
}else{
$('#chat').scrollTop( $('#chat').prop('scrollHeight'));
}
});
}
$('.textarea').keyup(function(e){
if( e.which == 13){
$('form').submit();
}
});
$('form').submit(function(){
var message = $('.textarea').val();
$.post('handlers/messages.php?action=sendMessage&message='+message, function(response){
//alert(response);
if(response==1){
LoadChat();
document.getElementById('messageFrm').reset();
}
});
return false;
})
</script>
</body>
</html>