/// <reference path="jquery-1.4.2-vsdoc.js"/>
/// <reference path="jquery-1.4.2.js"/>
$(function() {
// Bind the global ajaxStart event to the element
$("#divMsg").ajaxStart(function() {
$ (This). show (); // display element
})
// Bind the global ajaxStop event to the element
$("#divMsg").ajaxStop(function() {
Processing (this).html ("data processing has been completed. "). Hide ();
})
// Initialize the comment data
LoadData();
$ ("# Button1"). click (function () {// click "Post" button event
// Obtain the authenticated user name
var strName = encodeURI($("#txtName").val());
// Obtain the post content after the code is added
var strContent = encodeURI($("#txtContent").val());
$.ajax(
{
type: "GET",
Url: "AddData. aspx", // request to add a dynamic data page
dataType: "html",
data: { name: strName, content: strContent },
success: function(msg) {
alert(msg);
LoadData();
$("#txtName").val("");
$("#txtContent").val("");
}
})
})
/*
* Dynamically load comment data in XML format
*/
function LoadData() {
$.ajax(
{
type: "GET",
Url: "CommentData. xml", // request XML format data
dataType: "xml",
cache: false,
success: function(data) {
$ (". DivContent"). empty (); // clear the content in the tag first
Var strHTML = ""; // initialize and save the Content Variable
If ($ (data). find ("Data"). length = 0) {// if no data is found
StrHTML = "<div style = 'text-align: Center'> no comment data is found yet! </Div> ";
}
$ (Data). find ("Data"). each (function () {// traverse the obtained data
var $strUser = $(this);
strHTML += "<div class='clsShow'>";
StrHTML + = "<div class = 'showtitle'> netizen & nbsp; <a href =''> "+ $ strUser. find ("name "). text () + "</a> </div> ";
strHTML += "<div class='ShowContent'>" + $strUser.find("content").text() + "</div>";
StrHTML + = "<div class = 'showbottom '> sending time & nbsp;" + $ strUser. find ("date "). text () + "</div>"
strHTML += "</div>"
})
$ (". DivContent" character .html (strHTML); // display processed data
}
})
}
})
<?xml version="1.0"?>
<Comment>
<Data>
<name>Robot</name>
<Content> thank you! Thank you! Thank you! Thank you! </Content>
<date>16:36:20</date>
</Data>
</Comment>
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.IO" %>
<%
String strName = System. Web. HttpUtility. UrlDecode (Request ["name"]); // decode the comment User name
String strContent = System. Web. HttpUtility. UrlDecode (Request ["content"]); // decode the content submitted by the comment
string strFileName = "CommentData.xml";
// Define xml document Variables
XmlDocument xmlDoc = new XmlDocument();
// Open the specified xml document
xmlDoc.Load(Server.MapPath(strFileName));
// Find the root node Element
XmlNode xmlN = xmlDoc.SelectSingleNode("Comment");
// Add a node Element
XmlElement xmlE = xmlDoc.CreateElement("Data");
// Create a subnode
XmlElement xmlEn = xmlDoc.CreateElement("name");
// Set the node text
xmlEn.InnerText = strName;
// Add to Node
xmlE.AppendChild(xmlEn);
// Create a subnode
XmlElement xmlEc = xmlDoc.CreateElement("content");
// Set the node text
xmlEc.InnerText = strContent;
// Add to Node
xmlE.AppendChild(xmlEc);
// Create a subnode
XmlElement xmlEd = xmlDoc.CreateElement("date");
// Obtain the time, minute, and second
string strSendTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
xmlEd.InnerText =strSendTime;
// Add to Node
xmlE.AppendChild(xmlEd);
// Add the node to the root node
xmlN.AppendChild(xmlE);
// Save the created xml document
xmlDoc.Save(Server.MapPath(strFileName));
Response. Write ("your comment has been published! ");
%>