Regresar   Foros del Web > Programación para sitios web > AJAX

El registro es Gratis en Foros del Web
Respuesta
 
Herramientas Buscar en Tema Desplegado
Antiguo 05/05/08, 09:30:21   #1 (permalink)
farra tiene un saldo positivo de karma
 
Registrado: mar 2008
Ubicación: Aqui estoy
Mensajes: 153
farra is offline  
Pregunta como cargar pagina enviando el id del lugar donde cargar...?

soy nuevo en ajax... este codigo funciona si le quito los parametros a las funciones de dejo solo el parametro url... pero el problema es que asi siempre me carga en el mismo cuadro y yo quiero mandarle por parametro en que cuadro quiero que cargue...


les dejo el codigo:

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cuadros</title>
<Script>
function toggle(what) {
        var aobj = document.getElementById(what);
        if( aobj.style.display == 'none' ) {
               aobj.style.display = '';
        } else {
               aobj.style.display = 'none';
        }
}
function CrearXMLHttp(){
	XMLHTTP=false;
	if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	}else if(window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
// suponiendo que tu div se llama loading
function OpenPage(url,id){
	req=CrearXMLHttp();
	if(req){
		req.onreadystatechange = manejador(id);
		req.open("POST",url,true);
		req.send(null);
                toggle('loading'); // ojo aqui
	}
}
function manejador(id){
	if(req.readyState == 4){
		if(req.status == 200){
                        toggle('loading'); // ojo aca
			document.getElementById(id).innerHTML=req.responseText;
		}else{
			alert("Error"+req.statusText)
		}
	}
}
function cargacuadro(id){
var donde = document.getElementById("url").value;
var url = "ajaxtest.php?id="+donde;
OpenPage(url,id);
}
</Script>
</head>

<body>
<p>Codigo: 
  <label>
  <input name="url" type="text" id="url" value="" size="10" maxlength="10" />
  </label> 
  Cuadro: <a href="#" onclick="cargacuadro('1');">1</a>&nbsp;<a href="#" onclick="cargacuadro('2');">2</a>&nbsp;<a href="#" onclick="cargacuadro('3');">3</a>&nbsp;<a href="#" onclick="cargacuadro('4');">4</a></p>
<table width="100%" border="1">
  <tr>
    <td id="tdc_1"><div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
      </div></td>
    <td id="tdc_2"><div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
      </div></td>
  </tr>
  <tr>
    <td id="tdc_3"><div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
      </div></td>
    <td id="tdc_4"><div id="loading" style="display:none;" align="left">
          <table width="50" border="1" style="border-collapse:collapse;">
            <tr>
              <td bgcolor="#FF0000"><span style="color:#FFFFFF; font-weight:bold;">Cargando...</span></td>
            </tr>
          </table>
      </div></td>
  </tr>
</table>
</body>
</html>
no me funciona.. me tira un error... que dice 'no implementado' en la linea 27 caracter 3
  Responder Con Cita
Antiguo 05/05/08, 09:41:45   #2 (permalink)
Moderador
GatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karma
 
Registrado: may 2006
Ubicación: Queretaro, Mexico
Mensajes: 9.196
GatorV is offline  
Re: como cargar pagina enviando el id del lugar donde cargar...?

Cambia tu función así:
Código:
req.onreadystatechange = function() { manejador( id ); };
Tu problema es más que nada entender como funcionan las funciones anónimas en JavaScript, nada de AJAX en eso.

Saludos.

Saludos.
__________________
Blog Web
  Responder Con Cita
Antiguo 05/05/08, 13:18:11   #3 (permalink)
farra tiene un saldo positivo de karma
 
Registrado: mar 2008
Ubicación: Aqui estoy
Mensajes: 153
farra is offline  
Re: como cargar pagina enviando el id del lugar donde cargar...?

akbo de probar y sigue sin funcionar....

Código HTML:
<Script>
function toggle(what) {
        var aobj = document.getElementById(what);
        if( aobj.style.display == 'none' ) {
               aobj.style.display = '';
        } else {
               aobj.style.display = 'none';
        }
}
function CrearXMLHttp(){
	XMLHTTP=false;
	if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	}else if(window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
// suponiendo que tu div se llama loading
function OpenPage(url,id){
	req=CrearXMLHttp();
	if(req){
		req.onreadystatechange = function() { manejador( id ); }; // aca cambie
		req.open("POST",url,true);
		req.send(null);
                toggle('loading'); // ojo aqui
	}
}
function manejador(id){
	if(req.readyState == 4){
		if(req.status == 200){
                        toggle('loading'); // ojo aca
			document.getElementById(id).innerHTML=req.responseText;
		}else{
			alert("Error"+req.statusText)
		}
	}
}
function cargacuadro(id){
var donde = document.getElementById("url").value;
var url = "ajaxtest.php?id="+donde;
OpenPage(url,id);
}
</Script>
  Responder Con Cita
Antiguo 05/05/08, 21:42:08   #4 (permalink)
Moderador
GatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karma
 
Registrado: may 2006
Ubicación: Queretaro, Mexico
Mensajes: 9.196
GatorV is offline  
Re: como cargar pagina enviando el id del lugar donde cargar...?

¿Que error te marca ahora?

Saludos
__________________
Blog Web
  Responder Con Cita
Antiguo 06/05/08, 07:36:23   #5 (permalink)
farra tiene un saldo positivo de karma
 
Registrado: mar 2008
Ubicación: Aqui estoy
Mensajes: 153
farra is offline  
Re: como cargar pagina enviando el id del lugar donde cargar...?

Linea 37
Caracter 4
'document.getElementById(....)' es nulo o no es un objeto
  Responder Con Cita
Antiguo 06/05/08, 08:08:33   #6 (permalink)
Moderador
GatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karmaGatorV tiene un muy buen nivel de karma
 
Registrado: may 2006
Ubicación: Queretaro, Mexico
Mensajes: 9.196
GatorV is offline  
Re: como cargar pagina enviando el id del lugar donde cargar...?

En ese caso ahora el problema es que no encuentra el elemento que le pasas por tu Id, checa bien que si exista el elemento.

Saludos.
__________________
Blog Web
  Responder Con Cita
Respuesta


Califica este Tema - como cargar pagina enviando el id del lugar donde cargar...?.

Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado Califica este Tema
Califica este Tema:

Reglas del foro
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está activado
Las caritas están activado
Código [IMG] está activado
Código HTML está desactivado


Todas las horas son GMT -6. La hora es 06:40:22.

Message Board Statistics

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96