Foreach Ajax Json - Jquery
arrays, jquery, json
Solution
{"stars":["Chris Pine","Keira Knightley","Kevin Costner"]}
Change it to the above. You currently have an array inside an array.
Or do
$.each(data.stars[0], function(i, star) {
$('#stars').append('<input type="text" id="star" value="'+star+'" />');
});
If you expect to have multiple arrays in the outer array you have to do nested loops
Problem
Can anyone help me I have a Array ``` {"stars":[["Chris Pine","Keira Knightley","Kevin Costner"]]} ``` What i'm trying to do is foreach star i want to append a input to a div and foreach star with they're value inside the input this is what i've so far. ``` $.ajax({ type: "GET", url: 'ajax/get_details.php', data: {id: imdb_id}, dataType: 'json', success: function(data) { $.each(data.stars, function(i, star) { $('#stars').append('<input type="text" id="star" value="'+star+'" />'); }); }, }); ``` Can anyone tell me what i'm doing wrong please thanks