Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys,

I was able to pull this result from ajax in json format and print it on an html
JavaScript
[{"id":"207","Title":"Test","GenreName":"Action","EntryDate":"2014-05-06 19:13:14"}]


Now I cant figure out how to diplay this data in a table, with each columns for Id, Title, GenreName and EntryData. I cant find sample codes from google either. Or at least I cant comprehend what I saw there,.

Also if you'll notice the result have [] on it, on other examples I dont see Json format having that kind of style, I dont know where it came from since my controller only did echo the data from the model.

AJAX
JavaScript
$('form.ajaxForm').on('submit',function() {
                $.ajax({
                        type: 'POST',
                        url: 'http://localhost/AnimeInventory/index.php/maincontroller/testForAjax',
                        data:{ search: $("#searchInput").val(), searchType: $("#searchTypeID").val() },
                        dataType: 'JSON',
                        success: function(smg) {
                        }
                });
        });
        return false;


CodeIgniterController
PHP
public function testForAjax(){
        echo json_encode($this->inventoryModel->search()); 
        }


Thanks,
Posted
Updated 9-May-14 20:38pm
v2
Comments
DamithSL 10-May-14 2:35am    
update the question with how you do the ajax call and where you get this json value
KatsuneShinsengumi 10-May-14 2:38am    
I have the code block listed now.

1 solution

[] means ARRAY in json, you have array of objects in your json result. But array contains only one item.
few links for display json array in table

http://stackoverflow.com/questions/1051061/convert-json-array-to-an-html-table-in-jquery[^]
http://stackoverflow.com/questions/17066636/jquery-parsing-json-objects-for-html-table[^]

hope this helps you. :)
 
Share this answer
 
v2
Comments
KatsuneShinsengumi 10-May-14 2:42am    
Oh yeah, because in my model I return result_array. So that's why. Thanks,
DamithSL 10-May-14 2:44am    
Ok, i have added few links for you. you will find how to display json results in a table.
KatsuneShinsengumi 10-May-14 15:15pm    
Hi, I think this is useful if the table is going to be created for the data. I forgot to say that, there's already an existing table with values from database. What I need is to replace table's data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900