自从看了jQuery后,顿时感觉其的确很简单易学。下面就一把自己写的一个简易的聊天室程序写出来。
主要就是利用jQuery的ajax,然后,别的其实也没什么了。先上client端的程序吧。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" type="text/css" href="./styles/chat-mobile.css"/>
<script type="text/javascript" src="./scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(function() {
timestamp = 0;
updateMsg(timestamp);
$('button').click(function() { //重点是这里,从这里向服务器端发送数据
$.post('chat.php', {
'message': $('#msg').val(),
'name': $('#name').val(),
'timestamp': timestamp
},function(xml) {
$('#msg').val('');
addMe