<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>$.get()方法</title>
<script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<style type="text/css">
.container{
width: 60%;
margin: 0 auto;
border:1px solid #666;
}
.comment{
background-color: #cfcfcf;
}
</style>
</head>
<body>
<div class="container">
<form action="#" id="form1">
<p>评语:</p>
<p>姓名:<input type="text" name="username" id="username"/></p>
<p>内容:<input type="text" name="content" id="content"/></p>
<p><input type="button" value="提交" id="send"/></p>
</form>
<div class="comment">已有评论
<div id="resText"></div>
</div>
</div>
<script type="text/javascript">
$("#send").click(function() {
$.post('post.php', {
username:$("#username").val(),
content:$("#content").val()
},function(data,textStatus) {
var username=$(data).find('comment').attr('username');
var content=$(data).find('comment content').text();
var txtHtml="<div class='comment'><h6>"+username+"</h6><p class='para'>"+content+"</p></div>"+"\r\n";
$("#resText").append(txtHtml);
});
});
</script>
</body>
</html>
//加载post.php文档,代码如下
<?php
header("Content-Type=text/xml; charset:utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>".
"<comments>".
"<comment username='{$_POST['username']}'>".
"<content>{$_POST['content']}</content>".
"</comment>".
"</comments>";
?>