jquery and json - undefined

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

jquery and json - undefined

Post by GeXus »

I have the below jquery code calling a php page that's returning the below json code... the alert is undefined... Any idea what I'm doing wrong? Thanks!


jQuery:

Code: Select all

 
$.getJSON("lib/awsClass.php?asin="+$("#asin").val(),
        function(data){
          $.each(data, function(i,item){
 
                alert(item.EditorialReview);    
          });
});
 
 
Json code:

Code: Select all

 
{
    "EditorialReview": {
        "0": "Mad Catz\u00bf Microphone Stand for Rock Band features a slick, easy-to-use mic clip that allows for easy insertion and removal for those moments when you want to work the crowd. Constructed of durable aluminum with a wide-stance tripod base for stability, it\u00bfs also height-adjustable with a range of 38 to 53 inches. The stand also includes 3 unique controller clips that allow you to store your Xbox 360, Wii, PS3 or PS2 controller right on it, allowing you quick fingertip access for in-game navigation and setup. The included cable management clip will keep your mic\u00bfs cord from getting in your way when you\u00bfre belting out your favorite tracks."
    },
    "Title": {
        "0": "Universal Microphone Stand"
    }
}
 
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: jquery and json - undefined

Post by kaszu »

It should be

Code: Select all

alert(item["0"]);
because keys are "EditorialReview" and "Title"
Post Reply