All pastes #437843 Raw Edit

Untitled

public text v1 · immutable
·published 2007-04-13 09:09 UTC
rendered paste body
window.onload = initAll;

var xhr = false;

function initAll(){

	getNavigation("?page=6");

}

function getRecords(pars){

	makeRequestGET("../cgi-bin/get_content.php", pars);

	return false;

}

function getNavigation(pars){

	makeRequestGET("../cgi-bin/get_navigation.php", pars);

	return false;

}

function makeRequestGET(url, params){

	if(window.XMLHttpRequest){

		xhr = new XMLHttpRequest();

	}

	else {

		try {

            xhr = new ActiveXObject("Msxml2.XMLHTTP");

        } catch (e) {

            try {

               xhr = new ActiveXObject("Microsoft.XMLHTTP");

            } catch (e) {}

        }

	}

	

	if(xhr){

		xhr.onreadystatechange = showContents;		

		xhr.open('GET', url+params, true);

		xhr.send(null);

		

	}

	else{

		document.getElementById("area").innerHTML = "Sorry Couldnt make the HTTP request reqired by ajax";

	}

}

function showContents(){

	if(xhr.readyState == 4){

		if(xhr.status == 200){			

			if(xhr.responseXML && xhr.responseXML.conentType == "text/xml") {

				blurDisplay();//Deletes all the crap that was there before.

				//TODO::Logic for successfull request goes here!

				//Apparently its not responding with a successfull response!!

				var _xml = xhr.responseXML.getElementsByTagName("nav")[0];

				var _crumbs = _xml.getElementsByTagName("crumb");

				var _exLinks = _xml.getElementsByTagName("links");

				var _links = new Array();

				var i = 0;

				if((_crumbs != null) || (_crumbs.length >= 0)){

					//build crumbs

					for(i; i<_crumbs.length; i++){

						_links[i] = document.createElement("a");

						_links[i].value = _crumbs[i].getElementsByTagName("sitemode")[0].value;//Could use the setAttribute bub maybe not!

						_links[i].onclick = getNavigation(_crumbs[i].getElementsByTagName("params")[0].value);

					}					
				}

				if((_exLinks != null) || (_exLinks.length >= 0)){

					//build extra links

					for(i; i<_exLinks.length+i; i++){

						_links[i] = document.createElement("a");

						_links[i].value = _exLinks[i].getElementsByTagName("sitemode")[0].value;//Could use the setAttribute bub maybe not!

						_links[i].onclick = getNavigation(_exLinks[i].getElementsByTagName("params")[0].value);

					}
				}				

				for(var g=0; g<=i; g++){

					document.getElementById("ulNav").appendChild(_links[g]);
				}					

			}

			else{ 

				var outMsg = xhr.responseText;

				document.getElementById("ulNav").innerHTML = outMsg;

			}

			

			

		}

		else{

			var outMsg = "There was a problem with the request " + xhr.status;

			document.getElementById("ulNav").innerHTML = outMsg;

		}

		

	}

}

function blurDisplay(){

	document.getElementById("ulNav").innerHTML = "";//Clearing Mozilla First

	document.getElementById("ulNav").replaceNode(document.createTextNode(""));//Clearing IE

}