Web-simple start-Ajax + XML + DOM

Source: Internet
Author: User

Technical Exchange, DH explanation.

I am not engaged in web, so today's things should be quite simple.
A friend needs to implement this function.
Click More to obtain data from the server, and then display the data in the table.
I spent an hour writing an example. Here is an ugly look:

<Script language = "JavaScript"> // clear the table and pass in the table variable (DOM) function cleartable (t) {While (T. rows. length) {T. deleterow (0) ;}/// load string s to table t to function loadxml2table (S, T) {try {// ie xml = new activexobject ("Microsoft. xmldom "); XML. async = "false"; XML. loadxml (s);} catch (e) {try {// FF parser = new domparser (); xml = parser. parsefromstring (S, "text/XML");} catch (e) {alert ("XML cannot be loaded"); Return ;}// cleartab Le (t); // insert var x = xml. getelementsbytagname ("hh") for (I = 0; I <X. length; I ++) {newrow = T. insertrow (I); newrow. id = I; // X [I]. getelementsbytagname ("artist") [0]. childnodes [0]. nodevalue Newcell = newrow. insertcell (0); Newcell. innerhtml = x [I]. getelementsbytagname ("A") [0]. childnodes [0]. nodevalue; Newcell = newrow. insertcell (1); Newcell. innerhtml = x [I]. getelementsbytagname ("B") [0]. childnodes [0]. nodevalu E ;}} var XMLHTTP = NULL; // Ajax function loadxmldoc (URL) {XMLHTTP = NULL; If (window. XMLHttpRequest) {// code for all new browsers XMLHTTP = new XMLHttpRequest ();} else if (window. activexobject) {// code for ie5 and IE6 XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");} If (XMLHTTP! = NULL) {XMLHTTP. onreadystatechange = state_change; XMLHTTP. open ("get", URL, true); XMLHTTP. send (null);} else {alert ("your browser does not support XMLHTTP. ") ;}} function state_change () {If (XMLHTTP. readystate = 4) {// 4 = "loaded" If (XMLHTTP. status = 200) {// 200 = OK T = document. getelementbyid ("huangjacky"); If (t = NULL) return; S = XMLHTTP. responsetext; alert (s); loadxml2table (S, T);} else {alert ("problem retrieving XML data") ;}}</SCRIPT>

Give me a demo address. Haha
Http://thefiend.210131.0-168.net/1.html

That's all you need.

My name is DH. I am here today,

Related Article

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.