-1
$.post("Hirarchi/addHirarchi",
    {/*'id':hirarchiId,*/'hirarchiName':hirarchiName,'level':HirarchiLevel},
        function(data) {


            $('#lblMessage').html (data);
            $('#txtHirarchiName').val('');
            $('#txtHirarchiLevel').val('');

                        var data = $.parseJSON(data);

                        $.each(data, function(a,b,c) {


                            alert(data);

                        });

        });
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Salis Tariq
  • 93
  • 1
  • 1
  • 8
  • $.each(data, function(index,value,list) { alert(value); }); you can not pass object to alert. If you give object to it, it will [Object Object]. alert parameter must be string – Pankaj Parkar Jan 10 '15 at 06:48
  • if you want to alert data each time, you can JSON.stringify(data) – Pankaj Parkar Jan 10 '15 at 06:51

2 Answers2

0

Instead of print just data, print something like:

alert(JSON.stringify(data));

See, if that solves your problem.

Gaurav Dave
  • 6,838
  • 9
  • 25
  • 39
0

you can not pass object to alert. If you give object to it, it will [Object Object]. alert parameter must be string

//for Each loop code
$.each(data, function(index,value,list) { 
  alert(JSON.stringify(value)); //if you want to alert each object then use
  //data will not be accessible inside $.each you can access the same using 3rd parameter which list
  alert(JSON.stringify(list));
});

But the thing is why you gave alert in $.each and alerting same data. I'm assuming it is part of some functionality in your code. But that is not good practice to do.

Update 1.

Here is your answer with rendering table.

Code

drawTable(data);  /// call this line from your ajax success

function drawTable(data) {
    var tData = data.tblHirarchi
    for (var i = 0; i < tData.length; i++) {
        if (tData[i] != null) {
            drawRow(tData[i])
        }
    }
}

function drawRow(rowData) {
    var row = $("<tr />")
    $("#personDataTable").append(row); //this will append tr element to table... keep its reference for a while since we will add cels into it
    row.append($("<td>" + rowData[0] + "</td>"));
    row.append($("<td>" + rowData[1] + "</td>"));
    row.append($("<td>" + rowData[1] + "</td>"));
}

Fiddle HERE

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • {"tblHirarchi":[[2007,"ceo",1],[2078,"aa",11],[2079,"bb",22],null]} when i alert data it just alert like this but i want want to print only one row and one thing more how can i print the row of this data in a table row – Salis Tariq Jan 10 '15 at 07:05
  • #pankaj i just tried your code but alert(JSON.stringify(list)); alerts me UNDEFINED – Salis Tariq Jan 10 '15 at 07:07
  • no bro but now i want to print the data in a table row like a grid view – Salis Tariq Jan 10 '15 at 07:15
  • $.post("Hirarchi/addHirarchi",{/*'id':hirarchiId,*/'hirarchiName':hirarchiName,'level':HirarchiLevel}, function(data) { $('#lblMessage').html (data); $('#txtHirarchiName').val(''); $('#txtHirarchiLevel').val(''); }); i have recieving the table data in DATA but dont know how to print it in a table row – Salis Tariq Jan 10 '15 at 07:17
  • @SalisTariq i have attached fiddle. hope that will be helpful to you. – Pankaj Parkar Jan 10 '15 at 07:43
  • @SalisTariq have you checked my answer and fiddle..does it helpful to you? – Pankaj Parkar Jan 10 '15 at 08:04