Information Systems



How do I post/get using AJAX?

Here's an example that gets a select field dynamically using AJAX. genselector.jsp is a jsp file that gets the selector using java.

function getSelector(sid, cid, dw)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
// document.gen.op.value=xmlHttp.responseText;
curHtml = curParent.innerHTML;
curParent.innerHTML=xmlHttp.responseText;
// removeBrackets();
}
}
curCid = cid;
xmlHttp.open("GET","/genselector.jsp?sid="+sid+"&cid="+cid+"&dw="+dw,true);
xmlHttp.send(null);
}