Código PHP:
<html>
<head>
<script>
function Ajax()
{
//--------------------------
// Variables
//--------------------------
this.handler = false; //Objeto
//--------------------------
// Funciones
//--------------------------
this.conectar = function()
{
if(navigator.appName == "Microsoft Internet Explorer") {
try {
this.handler = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {
this.handler = new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {}
}
} else {
this.handler = new XMLHttpRequest();
}
}
this.estados = function()
{
if(this.handler.readyState == 1) {
document.getElementById('estado').innerHTML = "Cargando...";
} else if (this.handler.readyState == 4) {
document.getElementById('estado').innerHTML = "Finalizado...";
document.getElementById('carga').innerHTML = this.handler.responseText;
}
}
this.enviar = function(url, metodo, valores)
{
this.handler.open(metodo, url, true);
this.handler.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
this.handler.onreadystatechange = this.estados();
if(metodo.toUpperCase() == 'POST') {
this.handler.send(valores);
} else {
this.handler.send(null);
}
}
}
window.onload = function()
{
pagina = new Ajax();
pagina.conectar();
pagina.enviar('prueba.php', 'GET');
}
</script>
</head>
<body>
<div id="estado">En espera</div>
<div id="carga">Vacio</div>
</body>
</html>