// ajaxlib.js JavaScript Document
var xmlHttp
function GetEmployee()
//create new function
{
xmlHttp=GetXmlHttpObject()
//set variable
if (xmlHttp==null)
{
alert ("Your browser doesn’t support HTTP Request. please use Firefox, Internet Explorer, or Safari")
// if browser doesn’t support xmlHttp, show error message
}
var url="get_links.php"
//set javascript to go to file get_employee.php & order webserver to execute it
url=url+"?cmd=GetEmployee"
//send variable command to execute the script
url=url+"&sid="+Math.random()
//send random id
xmlHttp.onreadystatechange=FetchComplete
//if the state of xmlHttp change, go to FetchComplete function
xmlHttp.open("GET",url,true)
//use get method
xmlHttp.send(null)
}
function FetchComplete()
//this is our defined function to get the AJAX status
{
/*
there is 5 readystate status :
0=uninitialized
1=loading
2=loaded
3=interactive
4=complete
you can modify the status state at your own
*/
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
//if AJAX state is complete (4)
{
document.getElementById("Result").innerHTML=xmlHttp.responseText
//get element where the id is "Result", in this case it goes to the <div> tag
}
if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading")
//if AJAX state is loading (loading)
{
document.getElementById("Result").innerHTML="<img src=\"loading.gif\"/>Fetching the links, please wait...."
//get element where the id is "Result", in this case it goes to the <div> tag
//send the loading image (loading.gif) that show us the data is being prepared
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// check browser firefox, opera 8.0+, safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// browser Internet Explorer
try
{
// IE 6.0+
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
// IE 5.0
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
//return the value
}