-
Notifications
You must be signed in to change notification settings - Fork 2
/
index1.php
167 lines (142 loc) · 3.38 KB
/
index1.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
require_once('./conf.php'); ?>
<!DOCTYPE html>
<meta charset=utf-8>
<head>
<title>聊天室</title>
<style>
*{
margin:0;
padding:0;
font-family: "microsoft yahei";
}
.box{
margin: 20px auto;
width: 800px;
height: 500px;
padding:20px;
box-sizing:border-box;
border:1px solid #000;
}
h1{
text-align:center;
}
div#chat{
width: 750px;
height: 300px;
padding:5px;
margin:20px 0;
border: 1px solid #bbb;
overflow:scroll;
color:red;
}
.msg {
width: 600px;
height: 25px;
}
.btn,.btn2 {
border:none;
width: 80px;
height: 30px;
border-radius:3px;
cursor:pointer;
background:#4c8cf5;
color:#fff;
}
.btn2{
float:right;
background:#de5145;
}
.btn2:hover{
background:#cd3225;
}
.btn:hover{
background: #8ab4f9;
}
.name{
background:#5cb85c;
color:#fff;
border-radius:3px;
padding:3px;
font-size: 15px;
}
.time {
background:#ccc;
border-radius:3px;
font-size: 12px;
color:#fff;
}
input{
margin:0 10px;
}
</style>
</head>
<body>
<div class="box">
在线列表:
<div id="list" style=" width: 750px; height: 50px;"></div>
<h1>聊天室 </h1> 当前用户 <h2 id="usrname"><?php echo($_SESSION['username']) ?></h2>
<form>
<input id="clear" class="btn2" type="button" value="删除聊天记录"/>
<p></p>
<div id="chat"></div>
<input id="txtmsg" class="msg" type="text" name="msg" />
<input id="btn" class="btn" type="button" value="发送"/>
</form>
</div>
</body>
<script src="js/jquery-3.4.1.min (1).js"></script>
<script type="text/javascript">
$(function(){
var usrN =$("#usrname").val();
$.ajax({
url: './LoginUsr.php',
type: 'post',
data: {usrname : usrN},
async:true,
success: function(data){
}
});
},500);
count = 0;
var t = setInterval(get_chat_msg,1000);
// 获取每隔1000毫秒就请求一次会话信息
function get_chat_msg()
{
//获取聊天消息打印到消息框
$.get("./chat_recv.php",function(data){
$("#chat").html("");
var obj = eval("("+data+")");
var array = obj.result;
for(var i=0;i<array.length;i++){
var obj2 = eval("("+array[i]+")");
var time = "<span class = time>"+obj2.chatdate+"</span>";
$("#chat").append($("<p>"+time+obj2.username+":"+obj2.msg+"</p>"))
};
});
//将当前用户存入在线列表
//请求在线列表中的数据
//if($){}
//$("list").show(1000);
};
$("#btn").click(function(){
strmsg = $("#txtmsg").val();
$.ajax({
url: './chat_send.php',
type: 'post',
data : { msg : strmsg},
async : true,
success : function(msg){
$("#txtmsg").val("");
}
})
});
// 清空数据库信息$.get(URL,callback);
//必需的 URL 参数规定您希望请求的 URL。
//可选的 callback 参数是请求成功后所执行的函数名。
$("#clear").click(function(){
$.get("delete.php",function(msg){
});
});
</script>
</html>