| Server IP : 172.64.80.1 / Your IP : 172.69.17.157 Web Server : Apache System : Linux mail.federalpolyede.edu.ng 5.10.0-32-amd64 #1 SMP Debian 5.10.223-1 (2024-08-10) x86_64 User : federalpolyede.edu.ng_idh35skikv ( 10000) PHP Version : 7.4.33 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/federalpolyede.edu.ng/httpdocs_backup/chat/scripts/ |
Upload File : |
var lastTimeID = 1;
$(document).ready(function() {
getChatText();
$('#btnSendMsg').click( function() {
sendChatText();
$('#txtMessage').val("");
});
lastTimeID=1;
startChat();
//getChatText();
});
function startChat(){
setInterval( function() { getChatText(); }, 2000);
// lastTimeID=0;
}
function getChatText() {
var chatwith =$('#chatwith').val();
var urlx="scripts/refresh.php?lastTimeID=" + lastTimeID + "&chatwith=" + chatwith ;
//alert(urlx);
$.ajax({url:urlx, async: true, success: function(data){
// alert(data);
// $('#dvPleasWait').html(data);
var jsonData = JSON.parse(data);
var jsonLength = jsonData.results.length;
var html = "";
if (lastTimeID==1) lastTimeID=0;
for (var i = 0; i < jsonLength; i++) {
var result = jsonData.results[i];
lastTimeID=result.Chatid;
var reply="";
var uName =result.MsgFrom;
if (result.IsUser=="Yes")
{ reply="reply";
uName="You";}
html += '<div class="msg ' + reply + '" >' +
'<img width="25px" height="25px" src="' + result.UserImg + '"/>' +
'<div class="content" style="min-width:250px;" >' +
'<h3>' + uName + '<span> said:</span><small>' + result.Date_Sent + '</small></h3>' +
'<p>' + result.Msg + '</p>' +
'</div>' +
'</div>'
}
if (html!="")
{ $('#msgList').append(html);
$('#chatScroll').scrollTop( $('#msgList').height());
}
//alert("sssd");
}});
}
function appendChat(result){
var jsonData = JSON.parse(result);
var res = jsonData.results[0];
var html="";
html += '<div class="msg reply" >' +
'<img width="25px" height="25px" src="' + res.UserImg + '"/>' +
'<div class="content" style="min-width:250px;" >' +
'<h3>You<span> said:</span><small>' + res.Date_Sent + '</small></h3>' +
'<p>' + res.Msg + '</p>' +
'</div>' +
'</div>'
$('#msgList').append(html);
$('#chatScroll').scrollTop( $('#msgList').height());
}
function sendChatText(){
var chatInput = $('#txtMessage').val();
var chatwith =$('#chatwith').val();
if(chatInput != ""){
$.ajax({url:"scripts/submit.php?chattext=" + encodeURIComponent( chatInput ) + "&chatwith=" + chatwith, async: true, success: function(result){
//lastTimeID +=1;
appendChat(result);
//getChatText();
//$('#dvPleasWait').html(result);
//alert(result);
}});
}
}