Monday, December 3, 2007

Ajax Codes

ajax.js

*****************************************************
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
xmlHttp = new XMLHttpRequest();
}

var targId;
var targType = 0;
var flag=true;
function fnShowData(url,tagetId,targetType,flag)
{
targId=tagetId;
targType=targetType;
xmlHttp.open("GET", url, flag);
xmlHttp.onreadystatechange = updateTable;
xmlHttp.send(null);
}

function updateTable()
{
if (xmlHttp.readyState == 4)
{
document.getElementById(targId).innerHTML = xmlHttp.responseText;
if (targType > 0)
setTarget(targType);
}
}

var getData;
function fnGetData(url,flag)
{
xmlHttp.open("GET", url, flag);
xmlHttp.onreadystatechange = updateData;
xmlHttp.send(null);
return getData;
}

function updateData()
{
if (xmlHttp.readyState == 4)
getData = xmlHttp.responseText;
}
*****************************************************
save the file in ajax.js fileimport this file in to your webpage using script tag.Call function
fnGetData("your url",false);

post your comments for extra help
*****************************************************