-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.php
71 lines (55 loc) · 1.59 KB
/
chat.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
</head>
<?php
session_start();
?>
<body>
<div id="wrapper">
<h1 class="h1"><?php echo $_SESSION['username'] ?> chat </h1>
<div class="chat_wrapper">
<div id="chat"></div>
<form method="POST" id="messageFrm">
<textarea name="message" cols="30" rows="10" class="textarea"></textarea>
</form>
</div>
</div>
<script>
LoadChat();
setInterval(function() {
LoadChat();
}, 500);
function LoadChat() {
$.post('handlers/messages.php?action=getmessages', function(respone) {
var scrollpos = $('#chat').scrollTop();
var scrollpos = parseInt(scrollpos) + 520;
var scrollHeight = $('#chat').prop('scrollHeight');
$('#chat').html(respone);
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) {
if (response == 1) {
LoadChat();
document.getElementById('messageFrm').reset();
}
});
});
</script>
</body>
</html>