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

AYUDA CON createElement, appendChild, y AJAX

Estas en el tema de AYUDA CON createElement, appendChild, y AJAX en el foro de Frameworks JS en Foros del Web. tengo un problema con una funcion... estoy haciendo un simulador donde el usuario elige un numero determinado de indicadores y elige una ciudad de la ...
  #1 (permalink)  
Antiguo 10/08/2008, 21:33
 
Fecha de Ingreso: agosto-2008
Mensajes: 15
Antigüedad: 15 años, 8 meses
Puntos: 0
AYUDA CON createElement, appendChild, y AJAX

tengo un problema con una funcion... estoy haciendo un simulador donde el usuario elige un numero determinado de indicadores y elige una ciudad de la que quiere mostrar sus indicadores seleccionados

var URL="grupoIndicadoresCiudadDatos.php?Ciudad="+IdCi udad+"&Indicador="+Indicadores[j];
var DIV=document.createElement("div");
DIV.setAttribute("id","Indicador"+(j+1));
var Layer=DIV.getAttribute("id");
mandarObjeto(URL,Layer);
CapaElementos.appendChild(DIV);

mandarObjeto(URL,Layer); es la funcion AJAX que contiene

function mandarObjeto(URL,CAPA)
{
Ajax=crearAjax();
Ajax.open("GET", URL ,true);
Ajax.onreadystatechange=function()
{
if(Ajax.readyState==4)
{
if(Ajax.status==200)
{

Texto=unescape(Ajax.responseText);
TextoFinal=Texto.replace(/\+/gi," ");
document.getElementById(CAPA).innerHTML=TextoFinal ;

}else if(Ajax.status==404)
{
CAPA.innerHTML="La Direccion no existe";
}else
{
CAPA.innerHTML="Error: ".Ajax.status;
}

}else
{
document.getElementById(CAPA).innerHTML="Cargando Datos...<img src='./imagenes/loadings/loading.gif'>";
}//END Ajax.readyState
}//END FUNCION QUE PROCESARA EL CONTENIDO

Ajax.send(null);


el problema es que cuando ejecuto el simulador no me crea los divs se queda la imagen de Loaging.. solo me crea el ultimo appendChild... pero si le pongo un alert por cada ojeto que se manda si me crea todos los divs
  #2 (permalink)  
Antiguo 11/08/2008, 07:46
Avatar de foreverOdd  
Fecha de Ingreso: noviembre-2007
Ubicación: Caracas
Mensajes: 489
Antigüedad: 16 años, 5 meses
Puntos: 14
Respuesta: AYUDA CON createElement, appendChild, y AJAX

Hola marciano87

Quiza si utlizas prototype la vida se te simplifique un poco en cuanto a la creacion e insercion de elementos...

lee esto a ve que te parece:

http://prototypejs.org/api

http://prototypejs.org/api/element

un ejemplo:

ele = new Element('div', { id: 'secondContainer'+counter});
$('UN_DIV').insert({before:ele});
__________________
My path is lit by my own fire, I only go where I desire
  #3 (permalink)  
Antiguo 11/08/2008, 09:33
 
Fecha de Ingreso: agosto-2008
Mensajes: 15
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: AYUDA CON createElement, appendChild, y AJAX


mmm gracias man pero lo intenté y sigue igual.. quiero q cada vez que aumente J me cree un div y me lo agregue.. si me lo agrega pero no me imprime el contenido solo el del ultimo div... se queda la imagen de Loading..

var Listado=document.getElementById("txtLista2");
var NumeroCiudades=Listado.options.length;
var Ciudades=new Array(NumeroCiudades);

for(i=0;i<NumeroCiudades;i++)
{
Ciudades[i]=Listado.options[i].value;
//alert(Ciudades[i]);
}

var Indicador=document.getElementById("txtIndicador");
var IdIndicador=Indicador.options[Indicador.selectedIndex].value;

if(IdIndicador==0)
{
alert("Elija un indicador");
return;
}

var CapaElementos=document.getElementById(CAPA);

for(j=0;j<NumeroCiudades;j++)
{
var DIV=new Element("div",{"id": "Ciudad"+j});
CapaElementos.appendChild(DIV);
}

for(i=0;i<=1;i++)
{
if(i==1)
{
alert("Se mostrarán todas las coincidencias encontradas");
}

for(j=0;j<NumeroCiudades;j++)
{
var URL="./grupoCiudadesIndicadorDatos.php?Indicador="+IdIndi cador+"&Ciudad="+Ciudades[j];
//alert(URL);
mandarObjeto(URL,"Ciudad"+j);

}

}//END FOR

Me funcoina con EXPLORER pero no con FIREFOX

Última edición por marciano87; 11/08/2008 a las 13:54
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 01:52.