JQuery Study Notes [Ajax News Comment function] (6-3)

Source: Internet
Author: User

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Title> News Comment function </title>
    <script type="text/javascript" 
            src="Jscript/jquery-1.4.2-vsdoc.js">
    </script>
    <script type="text/javascript" 
            src="Jscript/jquery-1.4.2.js">
    </script>
    <link type="text/css" href="Css/css_Ajax.css" rel="Stylesheet" />
    <script type="text/javascript" src="Jscript/js_Ajax.js"></script>
<body>
     <div class="divFrame">
         <div class="divTitle">
<Span> latest reviews </span>
         </div>
         <div class="divContent">
         </div>
         <div class="divSubmit">
<Div class = "SubTitle"> comment <span id = "divMsg" class = "clsTip"> sending data request... </Span> </div>
             <div class="SubContent">
             
                 <textarea id="txtContent" rows="6" class="txt"></textarea>
                 <div class="SubBtn">
<Span style = "float: left"> User name: <input id = "txtName" type = "text" class = "txt"/> </span>
<Span style = "float: right"> <input id = "Button1" type = "button" value = "" class = "btn"/> </span>
                 </div>
             </div>
         </div>
    </div>
</body>

 

/// <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! ");
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.