Ajax (Asynchronous JavaScript and XML) is a technology that uses JavaScript and Extensible Markup Language (XML) to transmit or accept data between Web browsers and servers. It is mainly used in the development of RIA (rich Internet applications.
The XML problem is finally solved today. Finally, some old methods of Dom are used in Firefox. I will explain the method here.
Code:
VaR XMLHTTP; // defines an XMLHTTPRequest object.
VaR temp_url_arr = new array ()
VaR temp_title_arr = new array ()
VaR list_arr = new array ()
If (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ()
If (XMLHTTP. overridemimetype ){
XMLHTTP. overridemimetype ('text/xml ');
}
} Else if (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
// The above section judges the current browser version to define different XMLHttpRequest objects for XMLHTTP. If the server response does not have the XML mime-type header, some Mozilla browsers may not work properly. Therefore, XMLHTTP. overridemimetype ('text/xml') is required to modify the header.
Function getdata () {// read data
XMLHTTP. onreadystatechange = prasexml;
XMLHTTP. Open ("get", "xmldata2.xml", true );
XMLHTTP. Send (null );
}
Function prasexml () {// parse data
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
VaR xmldoc = XMLHTTP. responsexml;
VaR root = xmldoc. getelementsbytagname ('data'). Item (0)
// Use this method to take effect in Firefox. At least I have never succeeded in XPath.
For (VAR iroot = 0; iroot <root. childnodes. length; iroot ++ ){
// Alert (root. childnodes. Item (iroot ))
VaR pic_node = root. childnodes. Item (iroot)
For (ipic = 0; ipic <pic_node.childnodes.length; ipic ++ ){
VaR url_node = pic_node.childnodes.item (ipic)
For (iurl = 0; iurl <url_node.childnodes.length; iurl ++ ){
VaR OBJ = new object ()
OBJ. type = url_node.nodename
OBJ. content = url_node.childnodes.item (iurl). nodevalue
If (url_node.nodename = "url "){
Temp_url_arr.push (OBJ)
} Else if (url_node.nodename = "title "){
Temp_title_arr.push (OBJ)
}
}
}
}
Install_list ()
}
}
}
Function install_list () {// the collected data is loaded into the list_arr array.
List_arr = new array ()
VaR target_div = Document. getelementbyid ('catelog ');
Target_div.innerhtml = ""
For (VAR I = 0; I <temp_url_arr.length; I ++ ){
VaR OBJ = new object ()
OBJ. url = temp_url_arr [I]. Content
OBJ. Title = temp_title_arr [I]. Content
List_arr.push (OBJ)
}
For (VAR I = 0; I <list_arr.length; I ++ ){
Target_div.innerhtml + = "<a href = '# 'onclick = 'img _ loader (/" "+ list_arr [I]. URL + "/"); '> "+ list_arr [I]. title + "</a> <br> ";
}
}
Function img_loader (param1) {// Method for loading Images
VaR target_div = Document. getelementbyid ('pic ');
Target_div.innerhtml = "}