1

i have a ajax call that retreives data and its success portion looks like this:

success: function(data) 
{               
$("table.table").append("<tr><td>" + data.member_id + "</td><td>" + data.comment + "</td></tr>");
}

the data variable is holding this data

[{"member_id":"2","comment":"kkk"},{"member_id":"1","comment":"this is admin 2"},{"member_id":"2","comment":"kkk"},{"member_id":"1","comment":"this is admin"}]

but the problem im getting is that the table td's contain undefined text. how do i fix this?

the hardcoded table looks like this:

<table class="table"></table>

2 Answers 2

6

You should loop through the array, can use $.each utility function:

$.each(json, function(i, data){
     $("table.table").append("<tr><td>" + data.member_id + "</td><td>" + data.comment + "</td></tr>");
})  

http://jsfiddle.net/ADvCJ/

Sign up to request clarification or add additional context in comments.

Comments

0

You can use this

$.each(data, function(i,row){
  $("table.table").append("<tr><td>"+row['member_id']+"</td><td>"+row['comment']+"</td></tr>");
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.