Creating Categories in Blogger

Tuesday, August 01, 2006

"Ajax" in action

I've been playing for a while with the Ajax stuff. I think I will eventually work out the issue of having the complete categories list from the archives on the main page, but still need more testing.

For the moment, I copy below the Ajax Magic Spelling, and how to parse HTML code. Really impressive.



function getFile(pURL) {
if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=postFileReady;
xmlhttp.open("GET", pURL, true);
xmlhttp.send(null);
} else if (window.ActiveXObject) { //IE
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
if (xmlhttp) {
xmlhttp.onreadystatechange=postFileReady;
xmlhttp.open('GET', pURL, false);
xmlhttp.send();
}
}
}

// function to handle asynchronous call
function postFileReady() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
document.getElementById('theDivToLoad').innerHTML=xmlhttp.responseText;
}
}
}



if (window.ActiveXObject){
vXMLDoc = new ActiveXObject("Microsoft.XMLDOM");
vXMLDoc.async = false;
//IE uses the loadXML method when the source document is NOT XML
vXMLDoc.loadXML(xmlhttp.responseText);
}else if(document.implementation.createDocument){
//Firefox requires a parser object to read the text
var vParser = new DOMParser();
vXMLDoc = vParser.parseFromString(xmlhttp.responseText, "text/xml");
}
if(vXMLDoc == null) alert("XML Doc Load Failed");

0 Comments:

Post a Comment

<< Home