Ver Mensaje Individual
  #10 (permalink)  
Antiguo 28/02/2012, 11:54
augusto_jaramil
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 19 años, 10 meses
Puntos: 8
Respuesta: Problema con encoding

Hola de nuevo....

Juepucha, llevo como tres días con este cuento y no lo he podido resolver

Si alguien pudiera realizar una prueba con este código se lo agredecería

Código PHP:
<?
session_start
();

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

if (isset(
$_POST["accion"])) {
    
$ced $_POST["ced"];
    
$sql "SELECT trim(nombre) as nombre FROM maestro WHERE cedula='$ced'";
    if (
$res lee_todo($sql)) { //lee_todo funcion que ejecuta el query y regresa el resultado
        
$content = array("data" => $res,
                         
"sql" => $sql
                        
);
    }
    else {
        
$content = array("sql" => $sql,
                         
"msg" => "Error en query"
                        
);
    }
    
armaRespuesta($content);
    die;
}
muestra_forma();
die;

function 
armaRespuesta($content) {
    if ( !
function_exists('json_encode') ){
                   function 
json_encode($content){
                    
//require_once 'Services/JSON.php';
                    
require_once 'JSON.php';
                    
$json = new Services_JSON;
                    return 
$json->encode($content);
                }
    }
    else
        echo 
json_encode($content);
    die;
}

function 
muestra_forma() {
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=LATIN1" />
        <script language="javascript" type="text/javascript" src="js/jquery.js"></script>
        <script>
            $(document).ready( function () {
                $("#ced").change( function () {
                    ced = $("#ced").val();
                    datos = $("#prueba").serialize()+"&accion=envia";
                    $.ajax({
                        data: datos,
                        type: "post",
                        dataType: "json",
                        url: "c.php",
                        success: function(json) {
console.log(json);
                            $.each(json.data, function (clave, valor) {
                                $("#nom").val(valor.nombre);
                            });
                        }
                    });
                });
                return false;
            });
        </script>
    </head>
    <body>
        <form action="<?= $PHP_SELF?>" name="prueba" id="prueba" method="post">
            <input type="text" id="ced" name="ced" value="">
            <input type="text" id="nom" name="nom" value="">
        </form>
    </body>
</html>
<?
?>
El encoding que tiene la base de datos es LATIN1
En la columna nombre hay caracter Ñ y al existir dicho caracter me retorna el campo vacío (null)

Mil Gracias por su ayuda