I have written an ajax call:

                context: this,
                dataType: 'json',
                                        if(data_!= -1)
                                            $('#write_table').append('<p>Summary:<br><br>[FORM TABLE HERE]</p>');

In this "summary_page_data" i have written echo json_encode($skills);
SO it is returning array.
when i alert the return data,
it shows me [{"field_name":"Operating System","field_value":"Linux"},{"field_name":"Operating System","field_value":"Protocols"}]

Now i want to make an array of this return .
and print that array in table

But how to form an array of json return?

Recommended Answers

All 4 Replies

What you show in the question would appear to be the returned JSON, decoded then re-encoded (re-stringified).

It woud be more useful to see the raw JSON, which may or may not be the same as the re-encoded JSON. To do this, temporarily use dataType:'text', and alert (data_).

Thanks for your inputs
i did

$.getJSON('summary_page_data', function(data) {
        $('#write_table').append('<label for="Summary" style="width:170px!important;">Summary</label><br>');
        $.each(data, function(index) {


Be careful ...

  1. jq.append() doesn't work the way you think. .append('<p>') will append an entire p node and is equivalent to .append('<p></p>') or (more economically) .append('<p/>'). Although it is syntactically incorrect, .append('</p>') will append another etire p node.
  2. With regard to node hierarchy, populating a DOM from jQuery obeys the same rules as populating from HTML. A table element will only accept thead, tbody and tr nodes. Browsers are error-tolerant but the rendering of any other node type appended to a table is indeterminate - typically above the table.

I expect you want something like this :

$.getJSON('summary_page_data').done(function(data) {
    var $tbody = $('<tbody/>').appendTo('#write_table');
    $tbody.append('<tr><td><label for="Summary" style="width:170px!important;">Summary</label></td></tr>');
    $.each(data, function(index, item) {
        $tbody.append('<tr><td>' + item.field_name + ':' + item.field_value + '</td></tr>');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.