jquery_ajax 遇到问题
下边的代码里:运行后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>
<!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>
...全文
相关推荐
Ajax_Jquery_Demo
### 应用示例在"jsd1509_Ajax_Jquery_Demo"中,你可能找到以下示例:1.
ajax+Jquery实现文件图片上传
如果你需要进一步的指导或遇到具体问题,可以查阅相关的开发文档或在线教程。
jquery的ajax例子无错版
标题“jquery的ajax例子无错版”表明这是一个关于jQuery AJAX用法的示例,且已针对可能出现的编码问题进行了处理,确保在utf_8和gb2312两种常见字符编码下都能正常显示,避免了乱码问题
Jquery AJAX 用于计算点击率(统计)
不同版本的Jquery可能会有不同的API和功能,因此在使用Jquery时,需要确认所使用的版本。知识点七:跨域问题。AJAX操作通常涉及到跨域问题,即前端代码和后端代码不在同一个域中。
Ajax_JQuery.
在"11_Ajax_JQuery"的培训文档中,你可能会学到如何使用JQuery来创建Ajax请求,包括设置请求头、处理错误、使用缓存、设置超时等高级特性。


