shaik shaik - 5 months ago 36
JSON Question

Append HTML Table To Json Response In Codeigniter

Hi I Want to draw a table with json data which is my code I am getting correct json response but not able to draw a table in popup, Which is my Code

$(document).on('click','.details', function(){
var student_id = $(this).attr("id");
//alert(Id);
$.ajax({
url: "<?php echo base_url(user/details);?>",
type: "post",
data: {id:id},
success: function(data)
{
$.each(json, function (i,data) {
$("#fees_table").append( "<tr><td>" + data.name + "</td><td>" + data.first_name + "</td><td>" + data.last_name + "</td><td>" + data.user_name + "</td></tr>");
});

}
});
} );


Which is my controller

Answer

Change this

$.each(json, function (i,data) {
    //....
});

as

var data = $.parseJSON(data);
$.each(data, function () {
    //....
});

If you getting correct response then it should work

Comments