The XML file has Continents, and every continent has Countries and every country has Cities.
The first select box gets populated with all the Continents, when the user selects a continent the second select box gets populated accordingly with the countries and when a country is selected the third select box is populated with the cities.
The thing is that with the knowledge i have on AJAX so far i make an XMLHttpRequest each and every time, getting the whole response every time.
What would be the way to use the first response to go through the XML document any time needed?
Code: Select all
function populate_list(){
var url = "data.xml";
var http_request = getHTTPObject();
http_request.open("GET", url, true);
http_request.onreadystatechange = function() {
if(http_request.readyState == 4) {
if(http_request.status == 200){
GetContinents(http_request);
}
}
}
http_request.send(null);
}
function GetContinents(http_request){
var response = http_request.responseXML;
var root = response.documentElement;
var cities_list = root.getElementsByTagName("City");
var N = cities_list.length;
for(i=0;i<N;i++){
tempCont = cities_list[i];
tempname=tempCont.getElementsByTagName("name")[0].childNodes[0].nodeValue;
tempvalue=tempCont.getElementsByTagName("areafile")[0].childNodes[0].nodeValue;
addOption(document.getElementById("select_cont"),tempname,tempvalue);
}
http_request.abort();
}Having
Code: Select all
http_request = getHTTPObject();Thanks for any opinions you can offer.