First, create a DoComments. aspx page and a DealComments. ashx page (the Code basically has comments. If no comments are written, read the first few articles first !).
The Code on the Docomments. aspx page is:
Copy codeThe Code is as follows: <Title> </title>
<Script type = "text/javascript">
Var objXmlHttp = null;
Function CreateXMLHTTP (){
If (window. ActiveXObject ){
ObjXmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
} Else {
If (window. XMLHttpRequest ){
ObjXmlHttp = new XMLHttpRequest ();
} Else {
Alert ("XMLHTTP initialization error! ");
}
}
}
Function DoComments (){
Var data = "txtComments" + document. getElementById ("txtComment"). value;
CreateXMLHTTP ();
ObjXmlHttp. open ("POST", "DealComments. ashx", true );
ObjXmlHttp. onreadystatechange = function () {// call after the server responds
If (objXmlHttp. readyState> = 4 ){
If (objXmlHttp. status = 200 ){
Var result = objXmlHttp. responseText; // obtain the string returned by the server
If (result = "true "){
Var cTable = document. getElementById ("commentTable"); // The table object for receiving comments
Var newRow = cTable. insertRow (cTable. rows. length); // Add a row to the last row of the table.
Var cTd = newRow. insertCell (); // Add another column to the newly added row
CTd. innerHTML = document. getElementById ("txtComment"). value; // you can specify the column content as the post content.
} Else {
Alert ("objXmlHttp. status ");
}
}
}
}
ObjXmlHttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); // Add a custom HTTP header request
ObjXmlHttp. send (data); // send the request to the server
}
</Script>
</Head>
<Body>
Comment:
<Table id = "commentTable" style = "width: 600px; border: 1px solid #000;" border = "1"
Cellpadding = "0" cellspacing = "0">
<Tr>
<% -- <Td width = "30%" class = "style1"> User Name </td> -- %>
<Td>
Content
</Td>
</Tr>
</Table>
<Br/>
<Hr/>
<Table style = "width: 700px; border: 1px solid #000; text-align: left;" border = "1"
Cellpadding = "0" cellspacing = "0">
<Tr>
<Td>
Release content:
</Td>
</Tr>
<Tr>
<Td>
<Textarea id = "txtComment" cols = "60" rows = "10"> </textarea>
</Td>
</Tr>
<Tr>
<Td>
<Input type = "button" onclick = "DoComments ()" id = "btnComment" value = "publish comments"/>
</Td>
</Tr>
</Table>
</Body>
</Html>
The code in DealComments. ashx is as follows:Copy codeThe Code is as follows: public void ProcessRequest (HttpContext context)
{
String strComment = context. Request. Form ["txtComments"]; // obtain the uploaded content.
If (string. IsNullOrEmpty (strComment) // if not empty, true is returned.
{
Context. Response. Write ("true ");
}
Else
{
Context. Response. Write ("false ");
}
Context. Response. End ();
}
Easy! Beginner's shoes... haha, and this series is only suitable for beginners. Please do not laugh!