Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02/03/2012, 08:21
augusto_jaramil
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Otra Alternativa a json... cual?

Que tal Don andresdzphp,

Diusculpame la demora, hasta ayer tarde pude ir a hacer la prueba.

Te comento, funciono la vaina. Este es el código que estoy utilizando para las pruebas aplicando lo que me indicaste:

Código PHP:
<?
header
("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " gmdate"D, d M Y H:i:s" ) . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Content-type: text/html; charset=iso-8859-1");
header("Pragma: no-cache");

session_start();

include_once(
"lee_base.php");
include_once(
"configuracion/abrirbd.php");
include_once(
"JSON.php");

if (isset(
$_POST["accion"])) {
    
$json = new Services_JSON();
    
$ced $_POST["ced"][0];
    
$nom trim($_POST["nom"][0]);
    if (
strlen($ced) >)
        
$sql "SELECT cedula, trim(nombre) as nombre FROM maestro WHERE cedula='$ced'";
    else
        
$sql "SELECT cedula, trim(nombre) as nombre FROM maestro WHERE nombre LIKE '$nom'";
    
$res lee_todo($sql);
    
$content = array("sql" => $sql,
                     
"data" => $res
                    
);
    
$output $json->encode($content);
    print(
$output);
    die;
}
muestra_forma();
die;

function 
muestra_forma() {
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script language="javascript" type="text/javascript" src="js/jquery.js"></script>
        <script>
            $(document).ready( function () {
                $("input").change( function () {
                    datos = $("#depe").serialize()+"&accion=envia";
console.log(datos);
                    $.ajax({
                        data: datos,
                        type: "post",
                        dataType: "json",
                        cache: false,
                        async: true,
                        //contentType: "application/json; charset=iso-8859-1",
                        url: "c.php",
                        success: function(json) {
console.log(json);
                            $.each(json.data, function (clave, valor) {
                                $.each(valor, function (key, vr) {
                                    if (key == "cedula")
                                        $("#ced0").val(vr);
                                    if (key == "nombre")
                                        $("#nom0").val(vr);
                                });
                            });
                        }
                    });
                });
                return false;
            });
        </script>
    </head>
    <body>
        <form action="<?= $PHP_SELF?>" name="depe" id="depe" method="post">
            <td>Id: <input type="text" id="ced0" name="ced[0]" value=""></td>
            <td>Nombre: <input type="text" id="nom0" name="nom[0]" value=""></td>
        </form>
    </body>
</html>
<?
?>
Me queda una duda:
Tengo líos con el caracter Ñ: Este es un caso que me ha sacado la piedra en estos días.... Al ejecutar este código indicándole un Id el servidor realiza una consulta para obtener el nombre correspondiente. Si el nombre registrado en la base de datos es por decir algo PIÑEROS PEREZ PEDRO el nombre obtenido es PIхROS PEREZ PEDRO aunque al ver el console.log veo que la respuesta es PI\u0445ROS PEREZ PEDRO. Ahora, si hago la consulta por nombre ingreso PIÑEROS PEREZ PEDRO veo que la variable JQuery datos = $("#miforma").serialize(); su contenido queda

ced%5B0%5D=&nom%5B0%5D=PI%C3%91EROS+PEREZ+PEDRO&accion=envia

y al servidor ejecuta el query

({sql:"SELECT cedula, trim(nombre) as nombre FROM maestro WHERE nombre LIKE 'PI\xD1EROS PEREZ PEDRO' ORDER BY nombre", data:[]})

Pero no retorna datos.

Como podes ver, hay un lío en la codificación de ese caracter en todo lado.

Agradezxo de antemano su ayuda,

Un Cordial Saludo