This example includes
1. Clients use XMLHTTP to send requests to server Pages
2. Server Page background using C # DataSet to implement the operation of the database and get the results
3. The client uses the xmldoc to obtain the result which the XMLHTTP returns and carries on the operation to the result
Appendix
Common methods and properties of XMLHTTP
Common methods and properties of XmlDoc
=========================
Send XMLHTTP request to server side
=========================
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("Get", "default2.aspx", False, "", "");
Xmlhttp.send ();
======================
Server-side related data processing
======================
protected void Page_Load (object sender, EventArgs e)
{
Connecting to a database
SqlConnection myconn = new SqlConnection ("Data source=192.168.0.36;initial catalog=northwind; User Id=sa; Password=sa ");
SqlDataAdapter Myda = new SqlDataAdapter ("select Top 5 * from Orders", myconn);
DataSet myds = new DataSet ();
MyConn.Open ();
Myda. Fill (myds);
Myconn.close ();
Sending XML objects to clients
Response.ContentType = "Text/xml";
Response.Write (myDS. GETXML ());
Response.End ();
}
=============================================
XmlDoc gets the results returned by XMLHTTP and operates on the results
=============================================
XML objects processed from the server
var xmldom = new ActiveXObject ("Microsoft.XMLDOM");
Xmlhttp.responseXML.createProcessingInstruction ("xml", "Version=\" 1.0\ "encoding=\" "gb2312\");
XMLDOM = xmlhttp.responseXML.documentElement;
alert (xmldom.xml);
Through the XMLDOM operation results
var length = Xmldom.getelementsbytagname ("OrderID"). Length;
alert (length);
-----------------------------------Appendix----------------------------------
The following excerpts from the online to the original author's intention to organize and selfless to share the thanks
========
XMLHTTP
========
Open method
Contains 5 parameters, the first three are necessary,
The latter two are optional (provided when the server requires authentication).
The meaning of the parameter is as follows:
Http-method:http means of communication, such as Get or POST
URL: The URL address of the server that receives the XML data. The ASP or CGI program is usually indicated in the URL
Async: A Boolean identifier that indicates whether the request is asynchronous.
If this is an asynchronous communication method (TRUE), the client does not wait for the server to respond;
If it is synchronous (false), the client waits until the server returns the message before performing another operation
UserID user ID, for server authentication
Password user password for server authentication
After initializing the request object with the Open method, call the Send method to send the XML data
Send method
The parameter type is a variant, which can be a string, a DOM tree, or any stream of data.
The way to send data is divided into two types: synchronous and asynchronous.
In asynchronous mode, once the packet is sent, the send process is terminated and the client performs other actions;
In synchronous mode, the client waits until the server returns a confirmation message before the send process ends.
ReadyState properties in the XMLHTTP object
Can reflect the progress of the server in processing the request.
The client's program can set the corresponding event-handling method based on this state information.
Value Description
0 Response object has been created, but the XML document upload process has not yet ended
1 XML document already loaded
2 XML document already loaded, in process
3 Part XML document has been parsed
4 The document has been parsed and the client can accept the return message
Client receive response is implemented by XMLHTTP object's properties
ResponseText: Returns the message as a text string;
Responsebody: Returns the message as the content of the HTML document;
Responsexml: The return message is treated as an XML document and is used when the server response message contains XML data;
Responsestream: Treats the return message as a Stream object
=======
xmldoc
=======
Document Object Properties
The Document object properties that are available are listed below:
1. Async
2. Attributes
3. ChildNodes
4. DOCTYPE
5. Document. Lement
6. FirstChild
7. Implementation
8. LastChild
9. nextSibling
nodename
NodeType
1 2 nodevalue
ondataavailable
onreadystatechange
Ownerdocument.
ParentNode
ParseError
previoussibling
readyState
URL
validateonparse
2 () 2. XML
The following is a list of the methods available for the Document object.
1. Abort
2. appendchild
3. CloneNode
4. CreateAttribute
5. Createcdatasection
6. Createcomment
7. Createdocument.ragment
8. createelement
9. Createentityreference
CreateNode
Createprocessinginstruction.
createTextNode
getElementsByTagName
HasChildNodes
InsertBefore
Load
Loadxml
Nodefromid
Parsed
RemoveChild
ReplaceChild.
SelectNodes
selectSingleNode
Transformnode
Listed below are the events available to the Document object:
1. ondataavailable
2. onreadystatechange
Document Object Properties
The Document object properties that are available are listed below:
1. Async
2. Attributes
3. ChildNodes
4. DOCTYPE
5. Document. Lement
6. FirstChild
7. Implementation
8. LastChild
9. nextSibling
NodeName
NodeType.
NodeValue
ondataavailable
onReadyStateChange