Looping through JSON array with jQuery -


i trying loop through simple json array , display contents jquery. json data is:

 {    "cards":[       {          "title":"cat",          "spanishword":"gato"       },       {          "title":"dog",          "spanishword":"perro"       }    ] } 

here jquery using:

    var jqxhr = $.getjson("http://www.myurl.com/cards.js", function (data) {          $.each(data.cards, function (i, item) {             $(".list").append("<li id='" + cards[i].title + "'>" + cards[i].title + cards[i].spanishword + "</li>");         });     }); 

i pretty problem in each statement can't figure out wrong.

the problem inside loop, use cards[i] instead of data.cards[i].

you use item instead of data.cards[i].


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -