This article reveals the mystery of XMLHTTP. I like to use XMLHTTP, mainly because it can display any ActiveX class method to the customer. That is, you can let customers call your ActiveX control. ============================================================================================================================================================================================================= ========= This article reveals the mystery of XMLHTTP. I like to use XMLHTTP, mainly because it can display any ActiveX class method to the customer. That is, you can let customers call your ActiveX control. The most important thing is that all communications are done in the background. Use XMLHTTP to extend the accessibility of the database. When submitting a query application, use XMLHTTP to listen to the ASP listening (service) page, the ASP page explains the command and calls the method in the VB ActiveX control. This VB control uses an XML string to return the query result to the ASP service page, and then assemble the result into the XML format to return to the user. When making this series, you don't need to load the current web page. Users don't even know what the background is doing. The example source program is available at the end of this article. The example of this article on the system is: MS SQL Server, MS IE 5.0 , MSXML 3.0 parser, MS IIS - copy all ASP files, CSS, and myBooks.xml files in the example to the server A virtual path. Copy BookView.ASP, XML_Receive.ASP, MyBooks.xml, Default.css, and Book.css and other files to a virtual path to the server. Register WebClass.xmlControl (WebClass.dll) on the server. Set the SQL Server server name in the XML_RecEive.asp file. Set your username and password in the WebClass.xmlControl class. Take a look at XMLHTTP function: Client: Here is a code in the BookViewer.asp file, with XMLHTTP to access the PUBS database: var xmlhttp = new activeXObject ("msxml2.xmlhttp"); // Create XMLHTTP Object VAR Xmlcmd = ' XML Version = "1.0"?> The first parameter is an HTTP method (the most commonly used not "POST" is "get"). The second parameter points to the URL path to execute the instruction. The third parameter determines whether it is performed asynchronously. You can also add two parameters, namely, usernames, and passwords. In the above example, I use HTTP POST to call the XML_RecEive.asp page (I call it as a listening page), ask for synchronous inquiry (not doing anything before completing the query). The fourth line: issued an instruction and started working. Note: The instruction is made by the second line of code. Because the synchronous execution is used, only the results can only be returned. Listening page (XML_Receive.asp) Work Foundation I called this page as a listening page because it comes to the arrival of the XMLHTTP instruction at the server. After receiving the query request, it has three things. First, load the query request to XML DOM and parse the instructions and its parameters. Second, according to customer requirements, call the processing method of the background Active X control. The background Active X control returns the results with the XML string. Third, load the return result into the XML DOM and returned to the user with the Response object. [Translator Note: This is a very typical three-layer application that can be lifted. The above three steps are specifically implemented as follows: Listening page (first step - instruction parsing): The following is a piece of code in the XML_RecEive.asp file, which is commented later. This code is used to parse the received query instructions and parameters (Parameter1, Parameter2, Parameter3). The number of parameters can be arbitrarily increased. VAR DOC = Server.createObject ("msxml2.domdocument"); doc.load (request); // load XMLHTTP request to XML DOM for resolution VAR C1 = doc.childNodes.Item (1) .childNodes.Item (0) .attributes.Item (0) .text; // instruction var p1 = doc.childNodes.Item (0) .attributes.Item (1) .TEXT; // Parameter 1 var p2 = doc. ChildNodes.Item (1) .childNodes.Item (0) .attributes.Item (2) .text; // Parameter 2 var p3 = doc.childNodes.Item (1) .childnodes.Item (0) .attributes.Item (0) .attributes.Item 3) .Text; // parameter 3 IF (Doc.childNodes.Item (1) .childnodes.Length == 2) // Test XML VAR Passedxml = '' Doc.childNodes.Item (1) .childNodes.Item 1) .XML; VAR XMLRETURN = '; // Initialization Return value var DOC = NULL; // Release XML DOM Listening Page (Step 2 - Call the appropriate method of the background Active X control): The following is XML_RecEive.asp file A piece of code from the "GetTitlesxml" method. It creates an Active X object and calls the getTitLesXML () method to return the query result of the PUBS database. Remember, the result is to returned with an XML string. // ************* Function gettitlesxml *********************** if (c1 == "gettitlesxml) { Resultsxml = true; // load results XML string var objWC = server.createObject ("WebClass.xmlControl"); // Initialize VB control objwc.strserver = SQLServer; // Point to SQL Server server XMLReturn = objwc.gettitleSxml () ; // VB function, returning the title VAR OBJWC = NULL with an XML string; // Release the VB control} listening page (third step - return result): The following is a piece of code in the XML_Receive.asp file, return the query results Give the user. Here, the creation result DOM, load results to DOM, check whether the load is correct, and finally returns the result to the user. Note: It is the result of the Save method of XML DOM, which is response, which is represented to the result stream. Var Result = server.createObject ("msxml2.domdocument"); // Create a result XML Domif (ResultsXML) // Load XML string {result.LoadXML (XMLReturn); // Call LoadXML to load strings to DOM IF (C1 == "SaveMyBooks") Result.Save (server.mappath (p1)); // If necessary, save XML file} if (Result.ParseError.ErrorCode! = 0) // Analysis error {// Return Result XMLReturn = ' XML Version = "1.0"?> The XMLHTTP has another RESPONSETEXT method to load ordinary files. The second line: because XML DOM has been established, you can no longer need XMLHTTP. Third line: If an error, the listening page will return XML Version = "1.0"?>