Pages

Thursday, May 7, 2009

Ajax loader

we will use ajax loader in the case of where we need the page loading with out browser refresh.

just copy this code in your page. and call getpage LocationAds() function in your action button or anchor tag.

specify which page has to load

and specify the loading image path

(if you wanna get new loading images then visit http://www.ajaxload.info/ site and make your own loading images with different colors)

<------------------ code goes here--------------------------->

function getPageLocationAds(frm){

xmlhttp = false;
if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

if (xmlhttp!=null) {
//url="addAdvertise.do?logic=pageLocAdsList&pageId="+pageId+"&pageLocation="+pageLocation;
url="addAdvertise.do?logic=pageLocAdsList&pageId="+pageId+"&pageLocation="+pageLocation+"&sDate="+sDate+"&eDate="+eDate;
xmlhttp.onreadystatechange= function () { state_Change1(xmlhttp); };
//alert("Url : "+url);
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Cache-Control","no-cache, private, max-age=0");
xmlhttp.send(null);
//refresh();
} else {
alert("Your browser does not support XMLHTTP.");
}

}

function state_Change1(httpRequest1)
{
//alert('test');

if(httpRequest1.readyState==4)
{
if(httpRequest1.status==200)
{
//alert(httpRequest1.responseText);

document.getElementById('avail').innerHTML=httpRequest1.responseText;
}
else
{
alert("Error loading page\n"+ httpRequest1.status +":"+ httpRequest1.statusText);
}
}
else
{
document.getElementById('avail').innerHTML = '&ltimg src="http://www.blogger.com/flash/ajax-loader2.gif" /> Loading Content...';
}
}

replace &lt <>

'avail' is the div tag id of present page and we are just replacing the total response content in this div tag only.