Thursday, August 30, 2007

Simply Ajax Solution

No need any AJAX framework or fancy update panels, just by using some simple javascript you can get some cool Ajax effect, plus web service is not needed.




function GetSLEmailByID(controlID, pol_nbr)
{
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
try
{
document.getElementById(controlID).innerHTML = xmlHttp.responseText;
}
catch(e)
{
alert(controlID+"\n"+e.message);
}
}
}
xmlHttp.open("GET","slgetemail.aspx?pol=" + pol_nbr,true);
xmlHttp.send(null);
}


In this function, xmlHttp.onreadystatechange set a callback function, while xmlHttp.open("GET","slgetemail.aspx?pol=" + pol_nbr,true); initial the call of another page to get emails using a query string. So the whole content of the page will be parsed in the callback function and display the email.

No comments: