Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/09/2010, 14:33
Manuelfcg
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1
Antigüedad: 13 años, 8 meses
Puntos: 0
Inicio en AJAX

Hola amigos de foros del web. Estoy aprendiendo a programar en AJAX y me copié el siguiente ejemplo para ajecutarlo y analizarlo pero no me funciona:
<html>
<head>
<script type="text/javascript">
var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING = 1;
var READY_STATE_LOADED = 2;
var READY_STATE_INTERACTIVE = 3;
var READY_STATE_COMPLETE = 4;

var PeticionXmlHttp

function DescargaArchivo()
{
CargarContenido("/home/mcastro/ajax_info.txt", "GET", MuestraContenido);
}

function CargarContenido(Url, Metodo, Funcion)
{
PeticionXmlhttp = InicializarPeticionHttpRequest();

if (PeticionXmlhttp)
{
PeticionXmlHttp.onreadystateready = Funcion;
PeticionXmlHttp.open(Metodo, Url, true);
PeticionXmlHttp.send(null);
}
}

function InicializarPeticionHttpRequest
{
/*if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
else
if (window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}*/

var Obj;<html>
<head>
<script type="text/javascript">
var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING = 1;
var READY_STATE_LOADED = 2;
var READY_STATE_INTERACTIVE = 3;
var READY_STATE_COMPLETE = 4;

var PeticionXmlHttp

function DescargaArchivo()
{
CargarContenido("/home/mcastro/ajax_info.txt", "GET", MuestraContenido);
}

function CargarContenido(Url, Metodo, Funcion)
{
PeticionXmlhttp = InicializarPeticionHttpRequest();

if (PeticionXmlhttp)
{
PeticionXmlHttp.onreadystateready = Funcion;
PeticionXmlHttp.open(Metodo, Url, true);
PeticionXmlHttp.send(null);
}
}

function InicializarPeticionHttpRequest
{
/*if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
else
if (window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}*/

var Obj;

if (window.XMLHttpRequest)
{
Obj = new XMLHttpRequest();
}
else
{
try
{
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert('El navegador utilizado no está soportado');
}

return Obj;
}
}

function MuestraContenido()
{
if (PeticionXmlHttp.readyState == READY_STATE_COMPLETE) &&
PeticionXmlHttp.status == 200)
{
document.getElementById("myDiv").innerHTML = PeticionXmlHttp.responseText;
}
}

</script>
</head>

<body>

<div id = "myDiv">
<h2>Ajax va a cambiar este texto</h2>
</div>

<button type = "button"
onclick = "DescargaArchivo()">
Descargar contenido
</button>

</body>
</html>


if (window.XMLHttpRequest)
{
Obj = new XMLHttpRequest();
}
else
{
try
{
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert('El navegador utilizado no está soportado');
}

return Obj;
}
}

function MuestraContenido()
{
if (PeticionXmlHttp.readyState == READY_STATE_COMPLETE) &&
PeticionXmlHttp.status == 200)
{
document.getElementById("myDiv").innerHTML = PeticionXmlHttp.responseText;
}
}

</script>
</head>

<body>

<div id = "myDiv">
<h2>Ajax va a cambiar este texto</h2>
</div>

<button type = "button"
onclick = "DescargaArchivo()">
Descargar contenido
</button>

</body>
</html>

Cuando presiono el botón para probarlo, no hace nada. ¿Por qué?