Monday, June 27, 2011

Javascript

var loadingHtml = "

\"Loading...\"
";

function GetAsynchronousData(url, strDivName, chkLoader) {

//Place Loading HTML
document.getElementById(strDivName).innerHTML = loadingHtml;
document.getElementById(strDivName).style.visibility = "visible";

if (chkLoader) {
if (document.getElementById(strDivName).innerHTML.indexOf('moreLoader.gif') < 0) {
return;
}
}

InitXmlHttpRequest();

var handleStateChanged = function() {
if (xmlhttp.readyState == 4) { // 4 = "loaded"
if (xmlhttp.status == 200) { // 200 = OK
try {
//alert("message from server : " + xmlhttp.responseText);
document.getElementById(strDivName).innerHTML = xmlhttp.responseText;
}
catch (e) {
}
}
else {
//alert("Problem retrieving XML data");
}
}
};

if (xmlhttp != null) {
xmlhttp.onreadystatechange = handleStateChanged;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
else {
//alert("Your browser does not support XMLHTTP.");
}
}



var xmlhttp;

function InitXmlHttpRequest() {

xmlhttp = null;
if (window.XMLHttpRequest) {
// code for all new browsers
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
// code for IE5 and IE6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}

2 comments: