Client script by XMLHTTP
Do you have problems or puzzles in the Internet or Windows-based development? At this time, you can help Dr. Gui (Drgui@microsoft.com); Dr. Gui will be two guest MSDN each month, answer your questions online. Although the busy work arrangement made him unable to reply to all the questions, he will answer more questions as much as possible. If you just select your question, then doctors will send you a GUI Dr. T-shirt!
Summary: The method of using the client script writing to create a web page is to include the format and script using the system's XMLHTTP object, XML file, and XSL style sheet.
Dr. Gui's Bits and Bytes
This is the title of Dr. Gui's network diary. Unfortunately, recently did not add more content to this column. It may be because there is too much rain in Seattle, or the weather is too cold, or the sun is too violent, or it is delayed by some things.
But you may like to read the Alice in Blibbetland story there. Or is an unlucky egg Iloo.
In short, if you have something to say, please post your comment on the comments on the same day. Or write an email for Dr. Gui ...
Now, answer your questions!
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"?>
2. Then, create a file containing the following code and named BOOKS.XSL. This file is a style sheet referenced by Books.xml created in step 1. It contains the information necessary to correctly format the above XML file as an HTML page, even on the HTML page including a script.