mira tengo mis codigos:
Código PHP:
Ver original<html>
<head>
<title>Registro con AJAX</title>
</SCRIPT>
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
</head>
<body>
<form name="nuevo_empleado" action="" onsubmit="enviarDatosEmpleado(); return false">
<h2>Nuevo empleado</h2>
<p>rut empleado
<label>
<input name="rut_empleado" type="text" />
</label>
</p>
<p>nombre
<label>
<input name="nombre" type="text" />
</label>
</p>
<p>apellido
<label>
<input name="apellido" type="text" />
</label>
</p>
<p>tipo usuario
<SELECT name="tipo_usuario">
<OPTION VALUE="ADM" >Administrador
<OPTION VALUE="EMP" >Empleador
<OPTION VALUE="TAL" >Taller
</SELECT>
</p>
<p>password
<label>
<input name="password" type="text" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Grabar" />
</label>
</p>
</form>
<div id="resultado"><?php include('consulta.php');?></div>
</body>
</html>
luego un ajax
Código Javascript
:
Ver originalfunction objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}//fin catch(E)
}//fin catch (e)
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}//fin funcion objetoAjax()
function enviarDatosEmpleado(){
//donde se mostrará lo resultados
divResultado = document.getElementById('resultado');
//valores de los inputs
rut=document.nuevo_empleado.rut_empleado.value;
nom=document.nuevo_empleado.nombre.value;
ape=document.nuevo_empleado.apellido.value;
tipo=document.nuevo_empleado.tipo_usuario.value;
pass=document.nuevo_empleado.password.value;
//instanciamos el objetoAjax
ajax=objetoAjax();
//uso del medotod POST
//archivo que realizará la operacion
//registro.php
ajax.open("POST", "registro.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta capa
divResultado.innerHTML = ajax.responseText
//llamar a funcion para limpiar los inputs
LimpiarCampos();
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax.send("rut_empleado="+rut+ "&nombre="+nom+ "&apellido="+ape+ "&tipo_usuario="+tipo+ "&password="+pass)
}
function LimpiarCampos(){
document.nuevo_empleado.rut_empleado.value="";
document.nuevo_empleado.nombre.value="";
document.nuevo_empleado.apellido.value="";
document.nuevo_empleado.tipo_usuario.value="";
document.nuevo_empleado.password.value="";
document.nuevo_empleado.nombres.focus();
}
luego mi registro
Código PHP:
Ver original<?php
//Configuracion de la conexion a base de datos
include ('conexion.php');
//variables POST
$rut_empleado=$_POST['rut_empleado'];
$nombre=$_POST['nombre'];
$apellido=$_POST['apellido'];
$tipo_usuario=$_POST['tipo_usuario'];
//$tipo_usuario='ADM';
//var_dump($tipo_usuario);
$password=$_POST['password'];
//registra los datos del empleados
$sql="INSERT INTO empleados (rut_empleado,nombre, apellido,tipo_usuario, password) VALUES ('$rut_empleado','$nombre','$apellido','$tipo_usuario','$password')";
include('consulta.php');
?>
y finamente mi consulta
Código PHP:
Ver original<?php
//Configuracion de la conexion a base de datos
include('conexion.php');
//consulta todos los empleados
$sql="select * from empleados";
$query = pg_query($conexion, $sql);/*ejecuta la consulta*/ if(pg_num_rows($query)==0) echo"Sin registros";//verifico si hay o no registros //muestra los datos consultados
//haremos uso de tabla para tabular los resultados
?>
<table style="border:1px solid #FF0000; color:#000099;width:400px;">
<tr style="background:#99CCCC;">
<td>rut empleados</td>
<td>nombre</td>
<td>apellido</td>
<td>tipo usuario</td>
<td>password</td>
</tr>
<?php
if (($row)==0){
echo "Sin registros";}
echo " <tr>";
echo " <td>".$row['rut_empleado']."</td>";
echo " <td>".$row['nombre']."</td>";
echo " <td>".$row['apellido']."</td>";
echo " <td>".$row['tipo_usuario']."</td>";
echo " <td>".$row['password']."</td>";
echo " </tr>";
}
?>
</table>
en primer lugar se ejecuta el form que envia los datos al ajax y este envia a registro.php para ingresar los datos, pero ahora quiero hacer otro form con datos de clientes y de ese archivos envialos a una funcion del archivo ajax para luego llamar una funcion al registro.php para ingresarlos y no me funciona