0

I want to show data received from a remote JSON source on a HTML table.

This is part of the script I am using now

var loadData = function(){
                $.ajax({
                    type:"POST",
                    url:"http://......"
                }).done(function(data){
                    console.log(data);
                    var users = JSON.parse(data);
                    for(var i in users){
                        $("#content").append("<td>"+users[ i ]+"</td>");
                    }
                });

The console shows following output:

{"data":[["1","PMI-M-072"]]}  

On the first td tag appear 1,PMI-M-072 as value. But I need to show each array element on a td tag. How can I get each element value?

2
  • That code looks like you are using jQuery. I suggest adding this as a tag to your question. Commented Jul 26, 2016 at 16:55
  • @contradictioned, you are right Commented Jul 26, 2016 at 17:06

1 Answer 1

1

I think you'll want to do:

var users = JSON.parse(data)["data"];

instead of:

var users = JSON.parse(data);
Sign up to request clarification or add additional context in comments.

2 Comments

and then how do I get each element value?
If an element is always in the form ["1","PMI-M-072"], and "PMI-M-072" is the value you're looking for, do users[i][1]

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.