Small problem of using XSL in JS

Source: Internet
Author: User
Tags xslt

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.