-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpChat.php
73 lines (61 loc) · 1.96 KB
/
pChat.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
<?php
session_start();
include_once "pConnect.php";
include_once "pAssetConfig.php";
if(!isset($_SESSION["login"]))
header("Location:pLogin.php");
?>
<!-- page content -->
<div class="right_col" role="main">
<?php
include "pOwns.php";
?>
<div class="x_panel">
<div class="x_content">
<div class="col-md-12 col-sm-12 col-xs-12">
<table class="table">
<tbody>
<messages id="messageList"></messages>
<tr>
<td>
<form onsubmit="return false"><input id="message" type="text" class="form-control" placeholder="Mesajınız... Göndermek İçin Enter'a Basın."><button id="sendB" onclick="sendButton()" style="display:none;">Gönder</button></form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="row"> </div>
</div>
<!-- /page content -->
<script>
document.getElementById("message").autofocus = true;
var xhttp = new XMLHttpRequest();
setInterval(listenAndUpdate, 1750);
var input = document.getElementById("messageList");
input.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode == 13) {
alert("het");
}
});
function sendButton() {
send(document.getElementById("message").value);
listenAndUpdate();
}
function send(message){
document.getElementById("message").value = "";
xhttp.open("GET", "pChatAjax.php?s=" + message, false);
xhttp.send();
}
function listenAndUpdate(){
xhttp.open("GET", "pChatAjax.php?r=20", false);
xhttp.send();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
input.innerHTML = xhttp.responseText;
}
};
}
</script>