Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/10/2008, 10:12
sanga24
 
Fecha de Ingreso: octubre-2008
Mensajes: 4
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Problema en firefox con formulario dinamico en ajax

<?php include('lib.php');?><!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>_.::Panel de Clientes::._</title>
</head>
<body>
<div id="conteiner" style="text-align:center;width:280px;height:18;">
<table width="98%" cellpadding=2 cellspacing=2 class="estilotabla" style="border-top-style:dashed">
<caption id="tag">Numero_de_Mensajes</caption>
<tr><th class="estilocelda">Contratados </th>
<th class="estilocelda">Restantes </th></tr>

<tr><th><?php echo $numero_sms ?></th>
<th><?php echo $numero_sms ?></th></tr>
</table>
<table width=98% cellpadding=2 cellspacing=2 class="estilotabla" style="border-top-style:dashed">
<caption id="tag">Anuncios</caption>
<tr><th class="estilocelda"> Anuncion Actual </th>
<th class="estilocelda">Editar </th></tr>

<tr><th><?php echo $anuncio?></th>
<th><?php echo "<a style=\"text-decoration:underline;cursor:pointer;\" onclick=\"pedirDatos('".$id."')\">Click Aqui</a>";?></th>
</table>
</div>
</body>
</html>

En este codigo es el de tabla y el link que pide el formulario para actualizar

lo siguiente es como genero el objeto ajax y las funciones para pedirdatos (hacer consulta) y enviardatos(actualizar)

function objetoAjax(){
var xmlhttp=false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
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 enviarDatosEmpleado(){
//donde se mostrar? lo resultados
divResultado = document.getElementById('resultado');
divFormulario = document.getElementById('formulario');
divResultado.innerHTML= '<img src="barra.gif">Actualizando';

//valores de los cajas de texto
id=document.frmempleado.idempleado.value;
dep=document.frmempleado.departamento.value;


//instanciamos el objetoAjax
ajax=objetoAjax();
//usando del medoto POST
//archivo que realizar? la operacion ->actualizacion.php
ajax.open("POST", "actualizacion.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar los nuevos registros en esta capa
divResultado.innerHTML = ajax.responseText
//una vez actualizacion ocultamos formulario
divFormulario.style.display="none";


}
}
//muy importante este encabezado ya que hacemos uso de un formulario
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax.setRequestHeader("Connection", "close");
ajax.send("idempleado="+id+"&departamento="+dep)
}

function pedirDatos(idempleado){
//donde se mostrar? el formulario con los datos
divFormulario = document.getElementById('formulario');



//instanciamos el objetoAjax
ajax=objetoAjax();
//uso del medotod POST
ajax.open("POST", "consulta_por_id.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta capa
divFormulario.innerHTML = ajax.responseText
divFormulario.style.display="block";
}
}
//como hacemos uso del metodo POST
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando el codigo del empleado
ajax.setRequestHeader("Connection", "close");
ajax.send("idemp="+idempleado)
}


De aqui este codigo se va al siguiente:

<?php
include_once("cEmpleado.php");
//variables POST
$idemp=$_POST['idempleado'];

$dep=$_POST['departamento'];

sleep(2);
//actualiza los datos del empleados
$objempleado = new cEmpleado;
if ($objempleado->actualizar($idemp,$dep)==true){
include('inicio.php');
//header ("Location: inicio.php");
//echo "<div id=\"imp\">Anuncio actualizado! </div>.";
}
else{
echo "No se pudo actualizar";
}

?>

este codigo actualiza y envia de nuevo a la pagina de inicio que fue el primer codigo