-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
82 lines (70 loc) · 2.79 KB
/
app.js
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
setInterval(refreshChat, 2000);
var chatRequest = new XMLHttpRequest();
var chatstr = '';
chatRequest.open('GET','chat.json','false');
chatRequest.onload = function() {
var chatData = JSON.parse(chatRequest.responseText);
for(var key in chatData)
{
chatstr = chatstr + '<div class="input panel panel-success"><div class="panel-heading"><h5><img class = "img-circle" src="images/user.png" height = "9%" width = "5%">'+chatData[key].name+'</h5></div>'+'<div class="panel-body">'+chatData[key].msg+'</div></div>';
}
document.getElementById('panelChat').innerHTML = chatstr;
var panelChat = document.getElementById('panelChat');
panelChat.scrollTop = panelChat.scrollHeight;
};
chatRequest.send();
// var elem = document.getElementById('panelChat');
// elem.scrollTop = elem.scrollHeight;
////////////////////////////////////////////////////////
function refreshChat()
{
// var panelUsers = document.getElementById('panelUsers');
// panelUsers.reload();
// $('#panelUsers').empty();
// $('#panelUsers').load(document.URL + ' #panelUsers');
// var panelChat = document.getElementById('panelChat');
// panelChat.scrollTop = panelChat.scrollHeight;
var chatRequest = new XMLHttpRequest();
var chatstr = '';
chatRequest.open('GET','chat.json');
chatRequest.onload = function() {
var chatData = JSON.parse(chatRequest.responseText);
for(var key in chatData)
{
chatstr = chatstr + '<div class="input panel panel-success"><div class="panel-heading"><h5><img class = "img-circle" src="images/user.png" height = "9%" width = "5%"> '+chatData[key].name+'</h5></div>'+'<div class="panel-body">'+chatData[key].msg+'</div></div>';
}
document.getElementById('panelChat').innerHTML = chatstr;
};
chatRequest.send();
//document.getElementById("chats").scrollTop = document.getElementById("chats").scrollHeight;
}
////////////////////////////////////////////////////////////
function push()
{
var name = document.getElementById('name').value.trim();
var msg = document.getElementById('msg').value.trim();
document.getElementById('msg').value = "";
if (name == null || name =="" && msg == null || msg == "")
{
alert('Message Cannot be empty!');
}
else
{
var chatPush = new XMLHttpRequest();
chatPush.open("GET", "send.php?name=" + name + "&msg=" + msg, true);
chatPush.send();
// var chatRequest = new XMLHttpRequest();
// var chatstr = '';
// chatRequest.open('GET','chat.json');
// chatRequest.onload = function() {
// var chatData = JSON.parse(chatRequest.responseText);
// for(var key in chatData)
// {
// chatstr = chatstr + chatData[key].name + ': ' + chatData[key].msg + '\n' ;
// }
// document.getElementById('chats').innerHTML = chatstr;
// };
// chatRequest.send();
// document.getElementById("chats").scrollTop = document.getElementById("chats").scrollHeight;
}
}