W
windandwaves
Hi Folk,
I use AJAX to load some XML. When I get back to XML, I want to get a
piece of html that is within <info>... lots of html .... </info>
I want to use:
xmlDoc.getElementsByTagName('info');
but that just returns
[Object HTMLCollection]
How can I retrieve the data within it.
Thank you
Nicolaas
Here is my code:
var i = new Array();
var j = 0;
var jmax = 4;
var http_request = false;
var idname = 'GSmap';
function changemap() {
var variables = getformparameters(document.getElementById('mapform'),
'');
UpdateHtml('_GSmap2.php', 'GSmaptype=8' + variables);
initMapGSmap();
createGSlayer('GSmaptype=1' + variables);
//reset
j = 0;
i = new Array();
return true;
}
function getformparameters(obj, getstr) {
//gets all variables from a form
j++;
for (i[j]=0; i[j] < obj.childNodes.length; i[j]++) {
var newobj = obj.childNodes[i[j]];
tgname = newobj.tagName
if(tgname) {
tgname.toLowerCase;
if (tgname == "INPUT") {
var tvalue = newobj.value;
if(tvalue != 0 && tvalue != "") {
var ttype = newobj.type;
var tname = newobj.name;
if (ttype == "text") {
getstr += "&" + tname + "=" + tvalue ;
}
if (ttype == "checkbox") {
if (newobj.checked) {
getstr += "&" + tname + "=" + tvalue;
}
else {
getstr += "&" + tname + "=0";
}
}
if (ttype == "radio") {
if (newobj.checked) {
getstr += "&" + tname + "=" + tvalue;
}
}
}
}
if (tgname == "SELECT") {
var sel = newobj;
var tvalue = sel.options[sel.selectedIndex].value;
if(tvalue != 0 && tvalue != "") {
getstr += "&" + sel.name + "=" + tvalue;
}
}
}
if(newobj.childNodes.length > 0 && j < jmax) {
getstr = getformparameters(newobj, getstr);
}
}
j--;
return getstr;
}
function UpdateHtml(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
http_request.overrideMimeType('text/xml');
//http_request.overrideMimeType('text/html');
}
}
else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert('could not load data');
}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
var geturl = url + '?' + parameters;
document.getElementById(idname + 'title').innerHTML = "loading new map
.... " + geturl;
http_request.open('GET', geturl, true);
http_request.async = false;
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
var xmlDoc = http_request.responseXML;
var titlearray = xmlDoc.getElementsByTagName('title');
var infoarray = xmlDoc.getElementsByTagName('info');
var zoomarray = xmlDoc.getElementsByTagName('zoom');
var longitudearray = xmlDoc.getElementsByTagName('longitude');
var lattitudearray = xmlDoc.getElementsByTagName('lattitude');
var info = flattenhtmlobject(infoarray, "");
document.getElementById(idname + 'title').innerHTML =
titlearray[0].firstChild.nodeValue;
document.getElementById(idname + 'info').innerHTML = info;
alert(zoomarray[0].firstChild.nodeValue);
alert(longitudearray[0].firstChild.nodeValue);
alert(lattitudearray[0].firstChild.nodeValue);
}
else {
alert('There was a problem with the request.');
}
}
else {
}
}
function flattenhtmlobject(obj, output) {
output = titlearray[0].firstChild.nodeValue;
return output;
}
I use AJAX to load some XML. When I get back to XML, I want to get a
piece of html that is within <info>... lots of html .... </info>
I want to use:
xmlDoc.getElementsByTagName('info');
but that just returns
[Object HTMLCollection]
How can I retrieve the data within it.
Thank you
Nicolaas
Here is my code:
var i = new Array();
var j = 0;
var jmax = 4;
var http_request = false;
var idname = 'GSmap';
function changemap() {
var variables = getformparameters(document.getElementById('mapform'),
'');
UpdateHtml('_GSmap2.php', 'GSmaptype=8' + variables);
initMapGSmap();
createGSlayer('GSmaptype=1' + variables);
//reset
j = 0;
i = new Array();
return true;
}
function getformparameters(obj, getstr) {
//gets all variables from a form
j++;
for (i[j]=0; i[j] < obj.childNodes.length; i[j]++) {
var newobj = obj.childNodes[i[j]];
tgname = newobj.tagName
if(tgname) {
tgname.toLowerCase;
if (tgname == "INPUT") {
var tvalue = newobj.value;
if(tvalue != 0 && tvalue != "") {
var ttype = newobj.type;
var tname = newobj.name;
if (ttype == "text") {
getstr += "&" + tname + "=" + tvalue ;
}
if (ttype == "checkbox") {
if (newobj.checked) {
getstr += "&" + tname + "=" + tvalue;
}
else {
getstr += "&" + tname + "=0";
}
}
if (ttype == "radio") {
if (newobj.checked) {
getstr += "&" + tname + "=" + tvalue;
}
}
}
}
if (tgname == "SELECT") {
var sel = newobj;
var tvalue = sel.options[sel.selectedIndex].value;
if(tvalue != 0 && tvalue != "") {
getstr += "&" + sel.name + "=" + tvalue;
}
}
}
if(newobj.childNodes.length > 0 && j < jmax) {
getstr = getformparameters(newobj, getstr);
}
}
j--;
return getstr;
}
function UpdateHtml(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
http_request.overrideMimeType('text/xml');
//http_request.overrideMimeType('text/html');
}
}
else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert('could not load data');
}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
var geturl = url + '?' + parameters;
document.getElementById(idname + 'title').innerHTML = "loading new map
.... " + geturl;
http_request.open('GET', geturl, true);
http_request.async = false;
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
var xmlDoc = http_request.responseXML;
var titlearray = xmlDoc.getElementsByTagName('title');
var infoarray = xmlDoc.getElementsByTagName('info');
var zoomarray = xmlDoc.getElementsByTagName('zoom');
var longitudearray = xmlDoc.getElementsByTagName('longitude');
var lattitudearray = xmlDoc.getElementsByTagName('lattitude');
var info = flattenhtmlobject(infoarray, "");
document.getElementById(idname + 'title').innerHTML =
titlearray[0].firstChild.nodeValue;
document.getElementById(idname + 'info').innerHTML = info;
alert(zoomarray[0].firstChild.nodeValue);
alert(longitudearray[0].firstChild.nodeValue);
alert(lattitudearray[0].firstChild.nodeValue);
}
else {
alert('There was a problem with the request.');
}
}
else {
}
}
function flattenhtmlobject(obj, output) {
output = titlearray[0].firstChild.nodeValue;
return output;
}