jquery_ajax 遇到问题

EthanQ 2011-08-17 08:31:07
下边的代码里:运行后div里的内容不刷新,分析了一下觉得逻辑没问题,不知道是不是有些细节没处理。多谢了!


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>index.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

<style>
body {margin:0; padding:250px; border:1px solid; padding: 5px; overflow:auto;}
#messageWindow {height:250px; border: 1px solid; padding:5px; overflow:auto}
#wrapper {margin:auto:width:438px}
</style>

<script type="text/javascript" src="scripts/jquery-1.3.1.js"></script>

<script type="text/javascript">
$(function(){
timestamp = 0;
updateMsg();
$("#chatform").submit(function(){
$.post("backend.jsp", {
message:$("#msg").val(),
name:$("#author").val(),
action:"postmsg",
time:timestamp
}, function(xml,textStatus){
$("#msg").val("");
addMessages(xml);
});
return false;
});
});

function updateMsg() {
$.post("list.jsp",{time:timestamp},function(xml,textStatus) {
$("#loading").remove();
addMessages(xml);
});

setTimeout('updateMsg()',4000);
}

function addMessages(xml) {
//alert($("status",xml).text());
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);
});
}
</script>
</head>

<body>
<div id="wrapper">
<p id="messagewindow"><span id="loading">加载中...</span></p>
<form id="chatform">
姓名:<input type="text" id="author" size="50"/><br/>
内容:<input type="text" id="msg" size="50"/><br/>
<input type="submit" value="发送"/><br/>
</form>
</div>
</body>
</html>
...全文
61 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
飓风zj 2011-08-18
  • 打赏
  • 举报
回复
建议的你的ajax直接返回html比较好 还方便
LAVENDER0071 2011-08-18
  • 打赏
  • 举报
回复
用firebug debug下
EthanQ 2011-08-18
  • 打赏
  • 举报
回复
恩,谢谢了!
最后一个菜鸟 2011-08-18
  • 打赏
  • 举报
回复
还是自己调一下
EthanQ 2011-08-18
  • 打赏
  • 举报
回复
做的是一个实时刷新的网络聊天室,后台交付的数据是封装的xml,jquery ajax这块做的挺好,就用了。谢谢大家了!

87,909

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧