Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/11/2013, 09:51
PSPforever
 
Fecha de Ingreso: marzo-2008
Mensajes: 186
Antigüedad: 16 años, 1 mes
Puntos: 3
Pregunta Problema al leer un JSON por Ajax

Hola,

Al cargar por Ajax los datos de un json me pinta en pantalla el nombre, pero quiero que aparezca también el texto name. Es decir en lugar de "Pepito" me salga "Name : Pepito" por ej.

Dejo el código del json y del script:

Código Javascript:
Ver original
  1. { "people" : [
  2.   {
  3.     "name" : "Ben",
  4.     "url" : "http://benalman.com/",
  5.     "bio" : "I create groovy websites, useful jQuery plugins, and play a mean funk bass. I'm also Director of Pluginization at @bocoup."
  6.   },
  7.   {
  8.     "name" : "Rebecca",
  9.     "url" : "http://rmurphey.com",
  10.     "bio" : "Senior JS dev at Bocoup"
  11.   },
  12.   {
  13.     "name" : "Jory",
  14.     "url" : "http://joryburson.com",
  15.     "bio" : "super-enthusiastic about open web education @bocoup. lover of media, art, and fake mustaches."
  16.   }
  17. ] }

Script de Ajax:

Código Javascript:
Ver original
  1. $(document).ready(function(){
  2.     $('a').click(function(e){
  3.         $.ajax({
  4.             url     :   'people.json',
  5.             data     :  "nocache=" + Math.random(),
  6.             dataType :  'json',
  7.             timeout  :  6000,
  8.             success  :  function(data){
  9.                             //JSON.stringify(data);
  10.                             $.each(data.people, function(key, value){
  11.                                 $('<li>' + key + ' : ' + value.name + '</li>').appendTo('ul');
  12.                                 console.log(key + " : " + value);
  13.                             });
  14.             },
  15.             error    :  function(data,status,error){
  16.                             console.log(status + error);
  17.             }
  18.         });
  19.         e.preventDefault();
  20.     });
  21. });

Soy iniciado en Ajax y no doy con la solución, aunque sé que tengo que modificar el key que muestro con el elemento <li>, espero vuestra ayuda.

Gracias.