Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Inicio en AJAX

Estas en el tema de Inicio en AJAX en el foro de Frameworks JS en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 09/09/2010, 14:33
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1
Antigüedad: 13 años, 7 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é?
  #2 (permalink)  
Antiguo 11/09/2010, 05:24
Avatar de djsos  
Fecha de Ingreso: septiembre-2007
Ubicación: Madrid-España
Mensajes: 374
Antigüedad: 16 años, 7 meses
Puntos: 14
Respuesta: Inicio en AJAX

Este ejemplo si no has visto nada es un poco complicado prueba algo mas sencillo aun para hecer tus pinitos y pruebas; de todas formas he de decirte que si no me equivoco (y si lo hago que me corrija algun guru)las cabezeras de ajax para crear el elemento DOM las crea 3 veces¿?

Busca en la red encontraras ejemplos mejor estructurados que este mas faciles de entender y sobre todo en muchos casos explicados para que sirve cada cosa.

Un Saludo
__________________
Es de bien nacidos ser agradecidos.
Desarrollo de software a medida | TPV Comercios

Etiquetas: ajax, inicio
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:56.