function createXMLHttp()
{
var xmlhttp = false;
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function getRequestBody(oForm)
{
var aParams = new Array();
for (var i=0 ; i < oForm.elements.length; i++)
{
var sParam = encodeURIComponent(oForm.elements[i].name);
sParam += "=";
sParam += encodeURIComponent(oForm.elements[i].value);
aParams.push(sParam);
}
return aParams.join("&");
}
function sendPostRequest()
{
var oForm = document.forms[0];
var sBody = getRequestBody(oForm);
var xmlhttp = createXMLHttp();
xmlhttp.open("POST", oForm.action, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200)
{
// success
}
else
{
// failed
}
}
};
xmlhttp.send(sBody);
}