
27/06/2007, 13:45
|
 | | | Fecha de Ingreso: junio-2007 Ubicación: Santiago, Chile
Mensajes: 113
Antigüedad: 17 años, 9 meses Puntos: 3 | |
Re: Cargar Una Tabla De Registro Llamandola Desde Un Select estos son los tres archivos que hacen referencia al caso:
/************************************************** ******/
ajax.js
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function MostrarConsulta(datos){
divResultado = document.getElementById('resultado');
divResultado.innerHTML= '<img src="anim.gif">';
ajax=objetoAjax();
ajax.open("GET", datos);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
divResultado.innerHTML = ajax.responseText
}
}
ajax.send(null)
}
/************************************************** ****/
consulta.php
<?php
include_once("cEmpleado.php");
//Sleep deja inactivo el script por n segundos
//n es un parametro, en el ejemplo 1 segundo
//esto para poder apreciar el gif animado
sleep(1);
//creamos el objeto $objempleados de la clase cEmpleado
$objempleados=new cEmpleado;
//la variable $lista consulta todos los empleados
$consulta= $objempleados->consultar();
//muestra los datos consultados
echo "</p>Nombres - Departamento - Sueldo</p> \n";
while($row = mysql_fetch_array($consulta)){
echo "<p>".$row['nombres']." - ".$row['departamento']." - ".$row['sueldo']."</p> \n";
}
?>
/************************************************** ****/
index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Consulta Registro con AJAX</title>
<!-- referenciamos al archivo ajax.js donde se encuentra nuestra funcion objetoAjax-->
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
</head>
<body>
<!-- En "onsubmit" escribimos la función 'MostrarConsulta' que creamos en javascript,
con su parametro que es el archivo que vamos a mostrar, en este caso 'consulta.php'-->
<form name="consulta" action="" onSubmit="MostrarConsulta('consulta.php'); return false">
<label>
<input type="submit" value="Consultar" />
</label>
</form>
<div id="resultado"></div>
</body>
</html> |