Ok, I have cleaned up the code and fixed some errors in it. The problem I am having is with the timer. If you uncomment the alert it pauses after every record. when I replace it with setInterval it runs through the code but doesn't pause. First time using setInterval and any help will be appreciated.
// in the head
working example is at:
// in the head
Code:
var c=0;
var t;
function wait() {
document.getElementById('targetDiv').value=c;
c+=1;
}
function getData() {
var mozillaFlag = false;
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
mozillaFlag = true;
}
else if (window.ActiveXObject) {
XMLHttpRequestObject = new
ActiveXObject ("Microsoft.XMLHTTP");
}
if (XMLHttpRequestObject) {
XMLHttpRequestObject.open("GET", "xmlData/business.xml", true);
XMLHttpRequestObject.onreadystatechange = function() {
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
var xmlDocument = XMLHttpRequestObject.responseXML;
if(mozillaFlag) {
removeWhitespace(xmlDocument);
}
displayBusinesses(xmlDocument);
}
}
XMLHttpRequestObject.send(null);
}
//wait();
}
function displayBusinesses(xmldoc) {
var businessesNode, WbusinessNode, featuredNode, logoNode, nameNode, descriptionNode, contactNode;
businessesNode = xmldoc.getElementsByTagName("businesses");
WbusinessNode = xmldoc.getElementsByTagName("Fbusiness");
featuredNode = xmldoc.getElementsByTagName("featured");
logoNode = xmldoc.getElementsByTagName("logo");
nameNode = xmldoc.getElementsByTagName("name");
descriptionNode = xmldoc.getElementsByTagName("description");
contactNode = xmldoc.getElementsByTagName("contact");
var imagesFront = "<img src=";
var imagesBack = " />";
var linebreak = "\<br>";
var counter;
var temp= xmldoc.getElementsByTagName('featured');
var temp2 = document.getElementById("vars");
temp2.innerHTML="# of nodes in featured is: " + temp.length;
for (counter=0; counter < temp.length; counter++) {
//clearInterval(t);
//if (temp.length != last node of xml then execute code else if (temp.length = last node then go to first node.
featuredBusinesses = nameNode[counter].firstChild.nodeValue + linebreak + linebreak + imagesFront + logoNode[counter].firstChild.nodeValue + imagesBack;
featuredBusinesses1 = descriptionNode[counter].firstChild.nodeValue + contactNode[counter].firstChild.nodeValue;
var target = document.getElementById("targetDiv");
target.innerHTML=featuredBusinesses + featuredBusinesses1 + counter + "this is the value for t: " + t;
//alert("you are node number: " + counter); // when you uncomment this line it pauses after every record displayed but now with setInterval
//alert("t =: " + t);
t=window.setInterval('displayBusinesses()', 3000);
//alert("t =: " + t);
}
}
function removeWhitespace(xml) {
var loopIndex;
for (loopIndex = 0; loopIndex < xml.childNodes.length;
loopIndex++) {
var currentNode = xml.childNodes[loopIndex];
if (currentNode.nodeType == 1) {
removeWhitespace(currentNode);
if (((/^\s+$/.test(currentNode.nodeValue))) && (currentNode.nodeType == 3)) {
xml.removeChild(xml.childNodes[loopIndex--]);
}
}
}
}
Comment