jump to navigation

XMLHttpRequest Object – Javascript rocks! Monday, February 25, 2008

Posted by kalyanimath in Uncategorized.
trackback

I finally managed to put together a site for our local SQUASH Club – Hawthorn Recreation Squash Club

The requirements for the site was fairly basic, It has 4 pages with club specific information about location, teams, gallery & contact.

Since i didn’t want to invest too much on writing new code, I used javascript to leavarage on exisiting technology & bring things together. From reading CSV files to integrating with Google Maps, Javascript can so easily mash it all up together.

Here is a code snipett that uses the XMLHttpRequest Object to extract xml data from a http response stream -Javascript rocks!

//create the Cross-browser XMLHttpRequest object
function getFile(pURL,pFunc) {
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
        xmlhttp=new XMLHttpRequest();
        eval(‘xmlhttp.onreadystatechange=’+pFunc+’;');
        xmlhttp.open(“GET”, pURL, true); // leave true for Gecko
        xmlhttp.send(null);
    } else if (window.ActiveXObject) { //IE
        xmlhttp=new ActiveXObject(‘Microsoft.XMLHTTP’);
        if (xmlhttp) {
            eval(‘xmlhttp.onreadystatechange=’+pFunc+’;');
            xmlhttp.open(‘GET’, pURL, false);
            xmlhttp.send();
        }
    }
}

Comments»

No comments yet — be the first.