Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/06/2013, 09:38
Avatar de enlinea777
enlinea777
 
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 16 años
Puntos: 127
Respuesta: Leyendo json con jquery

Primero php limpio


Código PHP:
$resulset mysql_query($sql);

$arr = array();
while (
$obj mysql_fetch_object($resulset)) {
    
//$type = $obj['psr_options.name'];
        
    
$arr[] = array('lat' => $obj->latitude,
                   
'refID' => $obj->refID,
                   
'bedrooms' => $obj->bedrooms
                   
                   
                   
        
);
}

echo 
json_encode($arr); 
segundo lectura correcta
Código HTML:
Ver original
  1.     <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  2. </head>
  3.     <div id="placeholder"></div>
  4.     <script>
  5. function leyendo_json(data){
  6.     var output="";
  7.     $.each(data, function(cantidad, obj){
  8.      output = "<ul>";
  9.         for (var i=0; i <= cantidad; i++) {
  10.             output+="<li>"+data[i].refID + "</li>";
  11.         }
  12.         output+="</ul>";
  13.     });
  14.     $("#placeholder").html(output);
  15. }  
  16.     $(function(){
  17.         $.getJSON('foro_4442029_json.php',function(data){leyendo_json(data);});
  18.     });
  19.     </script>
  20. </body>
  21. </html>