这是我的简单聊天框的代码,基本上这是关于点击发送(输入)按钮它会将消息发送到数据库并且还为接收者创建通知但我想仅在用户不是时才创建通知这个页面就是/message.php。有什么方法我可以知道其他用户是谁?或者我正在尝试做什么的任何其他方法?
$(".chatbox input").on("click", function () {
var rly = $("#reply").val();
var send = "<?php echo $Sender?>";
$.ajax({
type: 'POST',
url: 'Message_chat.php',
data: {
repl: rly
},
dataType: 'json',
success: function (data) {
document.getElementById("reply").value = "";
populatedata(data, send);
},
error: e => console.log(e)
});
});
function fetchdata() {
var send = "<?php echo $Sender?>";
$.ajax({
type: 'GET',
url: 'Message_chat.php',
dataType: 'json',
success: function (data) {
populatedata(data, send);
notification();
}
});
}
function notification() {
var notify = "";
$.ajax({
type: 'GET',
url: 'notify.php',
dataType: 'json',
success: function (data) {
if (data == null)
{
document.getElementsByClassName("ncircle")[0].style.display = "none";
} else {
var len = data.length;
for (var i = 0; i < len; i++) {
if (data[i].nread == 0) {
notify += "<p>" + data[i].nby + " sent you a message</p>";
}
}
$("#myDropdown").html(notify);
if (data.length != 0) {
document.getElementsByClassName("ncircle")[0].style.display = "block";
$(".ncircle").html(len);
}
}
},
error: e => console.log(e)
});
}