Share sample code for JS to read XML data

Source: Internet
Author: User
In recent projects, due to access performance issues, internal pages and other static processes have been generated. However, some content in the project needs to be dynamic. according to the previous method, it should be that a dynamic script file will be called using JS. the front-end time was read by Red kids. it seems that some of the code in it is pretty good, and all JS calls XML data, XML can be directly generated using a dynamic script program. In recent projects, due to access performance issues, internal pages and other static processes have been generated. However, some content in the project needs to be dynamic. according to the previous method, it should be that a dynamic script file will be called using JS. the front-end time was read by Red kids. it seems that some of the code in it is pretty good, and all JS calls XML data, XML can be directly generated using a dynamic script program.

The XMl data format is as follows:

 
 
  
   
    
Liu Yifei
   
   
    
MingXing/LiuYiFei.htm
   
   
    
7A9D4B
   
  
  
   
    
Cai Yilin
   
   
    
MingXing/CaiYiLin.htm
   
   
    
FD0000
   
  
  
   
    
Zhang Nala
   
   
    
MingXing/ZhangNaLa.htm
   
   
    
7A9D4B
   
  
  
   
    
Zhang Shaohan
   
   
    
MingXiang/ZhangShaoHan.htm
   
   
    
0000FF
   
  
  
   
    
Zhang Liangying
   
   
    
MingXing/ZhangLiangYin.htm
   
   
    
7A9D4B
   
  
  
   
    
Li Yuchun
   
   
    
MingXing/LiYuChun.htm
   
   
    
7A9D4B
   
  
  
   
    
Xu Ruoxi
   
   
    
MingXing/XuLuXuan.htm
   
   
    
FD0000
   
  
 

The front-end JS script code is as follows:
// Obtain the top click rankings of websites

Var cdsales = new ActiveXObject ("Microsoft. XMLDOM "); // create the XmlDom object cdsales. async = true; // asynchronously load cdsales. onreadystatechange = LoadedSales; function LoadedSales () {var txt = ""; if (cdsales. readyState = 4) {if (cdsales. parseError. errorCode! = 0) {txt = "";} else {var bistmcdsales.doc umentElement. selectNodes ("item"); if (bi! = Null & bi. length> 0) {for (var I = 0; I
 
  
";}} Else {txt =" ";}}} else {txt =" ";}} sales. innerHTML = txt;} function LoadSalesDoc () {var Url = "/XML/Hot. xml "; cdsales. load (Url );}
 

The above Hot. Xml can be automatically generated using a program, as long as the output page is in Xml format. It seems that more and more websites have begun to use the p + JS + XML method for architecture, at least the static page can also dynamically read the database. I don't know if this is an Ajax concept.

The above is the details shared by the sample code for JS to read XML data. For more information, see other related articles in the first PHP community!

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.