1//Updates the chat
2function updateChat(){
3 $.ajax({
4
5 type: "GET",
6 url: "update.php",
7 data: {
8 'state': state,
9 'file' : file
10 },
11 dataType: "json",
12 cache: false,
13 success: function(data) {
14
15 if (data.text != null) {
16 for (var i = 0; i < data.text.length; i++) {
17 $('#chat-area').append($("<p>"+ data.text[i] +"</p>"));
18 }
19
20 document.getElementById('chat-area').scrollTop = document.getElementById('chat-area').scrollHeight;
21
22 }
23
24 instanse = false;
25 state = data.state;
26 setTimeout('updateChat()', 1);
27
28 },
29 });
30}
31
1var lastTimeID = 0;
2
3$(document).ready(function() {
4 $('#btnSend').click( function() {
5 sendChatText();
6 $('#chatInput').val("");
7 });
8 startChat();
9});
10
11function startChat(){
12 setInterval( function() { getChatText(); }, 2000);
13}
14
15function getChatText() {
16 $.ajax({
17 type: "GET",
18 url: "/refresh.php?lastTimeID=" + lastTimeID
19 }).done( function( data )
20 {
21 var jsonData = JSON.parse(data);
22 var jsonLength = jsonData.results.length;
23 var html = "";
24 for (var i = 0; i < jsonLength; i++) {
25 var result = jsonData.results[i];
26 html += '<div style="color:#' + result.color + '">(' + result.chattime + ') <b>' + result.usrname +'</b>: ' + result.chattext + '</div>';
27 lastTimeID = result.id;
28 }
29 $('#view_ajax').append(html);
30 });
31}
32
33function sendChatText(){
34 var chatInput = $('#chatInput').val();
35 if(chatInput != ""){
36 $.ajax({
37 type: "GET",
38 url: "/submit.php?chattext=" + encodeURIComponent( chatInput )
39 });
40 }
41}
42