
function createXMLHttp() {
    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        var aVersions = [ "MSXML2.XMLHttp.5.0",
           "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
           "MSXML2.XMLHttp","Microsoft.XMLHttp"];
           
        for (var i=0; i<aVersions.length; i++) {
            try {
                var oXmlHttp = new ActiveXObject(aVersions[i]);
                return oXmlHttp;
            } catch (oError) {
                //Do nothing
            }
        }
    } else
    throw new Error("XMLHttp object could not be created.");
}


function getURL(myUrl) {
    
    //create the XMLHttp object
    var oXmlHttp = createXMLHttp();
    //make an asynchronous GET request to myURL (asynchronous is defined as true)
    oXmlHttp.open("get", myUrl, true);
    
    //set some header info
    oXmlHttp.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    oXmlHttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
    
    //define onreadystatechange event handler
    //the readyState property of XMLHttp changes as the request goes through and the response is received; 4 means complete
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            //check whether the content was found (200) or not
            if (oXmlHttp.status == 200)
                alert("Data returned is: " + oXmlHttp.responseText);
            else
                alert("An error occurred: " + oXmlHttp.statusText);
                
            //get the text contained in myUrl
	    var sData = oXmlHttp.responseText;
	                
	    //get response headers
	    var sContentType = oXmlHttp.getResponseHeader("Content-Type");
	    if (sContentType == "text/xml")
	        alert("XML content received.");
	    else if (sContentType == "text/plain")
	        alert("Plain text content received.");
	    else if (sContentType == "text/html")
	        alert("HTML content received.");
	    else
	        alert("Unexpected content received. " + sContentType);
	        	        
        }
    };
    
    //send the request
    oXmlHttp.send(null);
    
}