Today's AjaxProgramThere is a small problem. I want to use XSL to display the returned XML, but there is always an error when I call the JS transformnode,
Prompt "the required data is not ready"
At that time, I thought that the readystate of requestobj (xhr object) was not completed yet, but before that, I had a judgment on readystate, so it was wrong.
Locate in docstyle. After checking that the style file is correct, the doc has not loaded the data completely when the file is locked to transformnode.
VaR Doc = New Activexobject ( " Msxml2.domdocument. 3.0 " );
Doc. loadxml (requestobj. responsetext );
VaR Docstyle = New Activexobject ( " Msxml2.domdocument. 3.0 " );
Docstyle. Load ("data. XSLT ");
Doc. transformnode (docstyle); // an error occurred.
Later I found that Dom also has the onreadystatechange and readysate attributes, but I used another method.
It uses an object called a free thread and feels a bit asynchronous.
Although troublesome, the advantage is that parameters can be added to XSL. 1 VaR Docstyle = New Activexobject ( " Msxml2.freethreadeddomdocument " );
2 Docstyle. async = False ;
3 Docstyle. Load ( " Data. XSLT " );
4
5 VaR Doctemplate = New Activexobject ( " Msxml2.xsltemplate " );
6 Doctemplate. stylesheet = Docstyle;
7
8 VaR Processor = Doctemplate. createprocessor ();
9
10 Processor. Input = Doc;
Processor. addparameter ("Index", "2"); // Add a parameter
11 Processor. Transform ();
12 VaR Res = Processor. output;
13 Divcontent. innerhtml = res;