var oXmlHttp=false;
try
{
oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try
{
oXmlHttp = new XMLHttpRequest();
}
catch(e)
{
alert("Erro: Este browser não tem recursos para uso do Ajax!");
}
}
}
function goAjax(url, metodo, modo, tagRetorno, parametros) {
document.getElementById(tagRetorno).innerHTML='
';
if(metodo == "GET") {
oXmlHttp.open("GET", url, modo);
} else {
oXmlHttp.open("POST", url, modo);
oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
oXmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
oXmlHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
oXmlHttp.setRequestHeader("Pragma", "no-cache");
}
oXmlHttp.onreadystatechange = function() {
if(oXmlHttp.readyState == 4)
{
if (oXmlHttp.Status == 200 || oXmlHttp.Status == null )
{
retorno=oXmlHttp.responseText
document.getElementById(tagRetorno).innerHTML=unescape(retorno)
}
else if (oXmlHttp.Status == 404)
{
document.getElementById(tagRetorno).innerHTML = "Atenção! - Página não econtrada
";
}
else if(oXmlHttp.Status == 1223)
{
document.getElementById(tagRetorno).innerHTML = "Atenção! - a página solicitada não retornou nenhum conteudo
";
}
else
{
//retorno=oXmlHttp.responseText
//document.getElementById(tagRetorno).innerHTML=retorno
document.getElementById(tagRetorno).innerHTML = "Ocorreu exceção " + oXmlHttp.responseText + "
"
}
}
}
if(metodo == "GET") {
oXmlHttp.send(null);
} else {
oXmlHttp.send(parametros);
}
}
function goAjax2(url, metodo, modo, tagRetorno, parametros) {
document.getElementById(tagRetorno).innerHTML='';
if(metodo == "GET") {
oXmlHttp.open("GET", url, modo);
} else {
oXmlHttp.open("POST", url, modo);
oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
oXmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
oXmlHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
oXmlHttp.setRequestHeader("Pragma", "no-cache");
}
oXmlHttp.onreadystatechange = function() {
if(oXmlHttp.readyState == 4)
{
if (oXmlHttp.Status == 200 || oXmlHttp.Status == null )
{
retorno=oXmlHttp.responseText
eval(unescape(retorno))
}
else if (oXmlHttp.Status == 404)
{
document.getElementById(tagRetorno).innerHTML = "Atenção! - Página não econtrada
";
}
else if(oXmlHttp.Status == 1223)
{
document.getElementById(tagRetorno).innerHTML = "Atenção! - a página solicitada não retornou nenhum conteudo
";
}
else
{
//retorno=oXmlHttp.responseText
//document.getElementById(tagRetorno).innerHTML=retorno
document.getElementById(tagRetorno).innerHTML = "Ocorreu exceção " + oXmlHttp.responseText + "
"
}
}
}
if(metodo == "GET") {
oXmlHttp.send(null);
} else {
oXmlHttp.send(parametros);
}
}
function enviaPagina(url, metodo, modo, tagId, parametros)
{
if (metodo == "GET")
{
url = url+"?"+parametros+"&rnd="+ Math.random();
}
else
{
url = url+"?rnd="+ Math.random();
}
goAjax(url, metodo, modo, tagId, parametros);
}
function enviaPagina2(url, metodo, modo, tagId, parametros)
{
if (metodo == "GET")
{
url = url+"?"+parametros+"&rnd="+ Math.random();
}
else
{
url = url+"?rnd="+ Math.random();
}
goAjax2(url, metodo, modo, tagId, parametros);
}
function CriaXMLHTTP()
{
var ajax;
try
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try
{
ajax = new ActiveXObject("Msxml2.XMLHTTP");
alert(ajax);
}
catch(ex)
{
try
{
ajax = new XMLHttpRequest();
}
catch(exc)
{
alert("Esse browser não tem recursos para uso do Ajax");
ajax = null;
}
}
return ajax;
}
var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
for (var i=0; i < arrSignatures.length; i++)
{
try
{
var oRequest = new ActiveXObject(arrSignatures[i]);
return oRequest;
}
catch (oError)
{
}
}
throw new Error("MSXML não instalado.");
}
function ExecutaPagina(cPagina, cTagRetorno, cParametros)
{
document.getElementById(cTagRetorno).innerHTML='';
// Instancia o objeto XMLRequest
var oPagina = createXMLHTTP();
oPagina.open("post", cPagina, true); // Aqui vai para a nossa página que possui os dados na combo quando selecionar um registro na lista
// Para solicitações utilizando o método post deve ser acrescentado este cabecalho HTTP
oPagina.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// A função abaixo é executada sempre que o estado do objeto muda onreadystatechange. Ou seja, quando ler o que tem no arquivo
oPagina.onreadystatechange=function(){
if (oPagina.readyState==4)
{
// Abaixo o texto do gerado e colocado na Tag de retorno
document.getElementById(cTagRetorno).innerHTML = oPagina.responseText;
}
}
// Abaixo é enviada a solicitação. a configuração do evento onreadystatechange deve ser feita antes do send.
oPagina.send(cParametros);
}