日期:2014-05-17 浏览次数:20424 次
$(function () {
timestamp = 0;
updateMsg();
$("#chatform").submit(function () {
$.post("chatroom.aspx", {
message: $("#msg").val(),
name: $("#author").val(),
action: "postmsg",
time: timestamp
}, function (xml) {
$("#msg").val("");
addMessages(xml);
});
return false;
});
function addMessages(xml) {
if ($("status", xml).text() == "2") return;
timestamp = $("time", xml).text();
$("message", xml).each(function () {
var author = $("author", this).text();
var content = $("text", this).text();
var htmlcode = "<strong>" + author + "</strong>:" + content + "<br/>";
$("#messagewindow").prepend(htmlcode);
});
};
function updateMsg() {
$.post("chatroom.aspx", { time: timestamp }, function (xml) {
$("#loading").remove();
addMessages(xml);
});
setTimeout('updateMsg()', 4000);
}
})