Create an XMLHTTP with JScript HTML
Dear Dr. Gui:
I have a question about XML. I published an ASP page via XMLHTTP and send data as HTML and execute Object.innerHTML on the DIV, Table cell, or any element.
The problem I encountered is, once, I created a form on the ASP server page and send the form with HTML back, so everything is normal. But I also want to verify the page, so I put a JScript page link to the text of the response HTML in the HTML I intend to send back. After doing this, the script can't run.
When I include the actual JScript SRC reference on the parent page, it can run normally. This is because JScript code is not loaded to the running library? Can you not return JScript code when responding to XMLHTTP POST and working properly? Can I instantly generate JScript functions for the page created?
I haven't tried to do this with another way: I will release XML data via XMLHTTP, and then send it back as XML data, and then use the XSL style sheet to convert. I guess, you can define the JScript function in that way. But this way seems too complicated. Do you have any suggestions or answers?
Thank you
Peter Sung
Dr. Gui Reply:
Yes, Peter, you can return Microsoft JScript code when responding to XMLHTTP Post / Get, and make the code to be executed. This is just like a piece of cake first, then eat it. Just like you guess, the best way to do this is to use the XSL style sheet; once you make all types of restore normal, this is easy. Dr. Gui can even provide a shortcomings. (Of course, there are other solutions. As long as the response contains the correct header and characters in the correct order, the browser will interpret response to respond to normal work. If necessary, you can use a string connection to generate a response.)
In the following example, Dr. GUI uses JScript to client code and VBScript (Microsoft Visual Basic scripting) in the ASP page. The adopted strategy is this: XML file only contains data (and reference to the style sheet). The XSL file contains all HTML formats that make up the full page (including a script located in the appropriate location). The ASP page mainly includes several calls to create an XMLHTTP object, load the XML file into the object (using implicit style sheet) and write the result HTML to the response stream.
To try this method, do the simple steps shown below. Use Notepad to copy and paste and save all files in C: / INETPUB / WWWROOT.
1. Create a file containing the following XML text and named books.xml. Write down the reference to the Books.xsl style sheet. In addition, this file contains only data. xml version = "1.0"?> Xml-stylesheet type = "text / xsl" href = "books.xsl"?>