Miyazaki Ahmad
Miyazaki Ahmad

Reputation: 139

jQuery - Get data from table row and post it

I have a table listing student information with a column for a button to delete the student from that table and insert it to another table.

What I want to do for now is to get the data of a row and post it to another php file for me to do a query there. Even one data would be enough if I can't get data from each <td>, e.g. student_id, which is echoed in the first <td>.

I don't know how else to manipulate the code inside [[...]]

$('.btnRestore').click(function(){
    msg = "The student information will be restored to table X. \nProceed?";
    if (confirm (msg ))
    {
        [[var $row = $(this).closest("tr"),       
             $tds = $row.find("td");
        data  = $tds;]]
        $.post('process/another.php',data,function(view){
                $('#notis').html(view).show(0);
            });
    }
    });

Upvotes: 0

Views: 622

Answers (1)

Barmar
Barmar

Reputation: 780974

You can get an array of the text of all the TDs with:

data = $tds.map(function(td) {
    return td.text();
}).get();

$.post('process/another.php', { data: data }, function(view) {
    $("#notis").html(view).show();
});

In the PHP file, $_POST['data'] will be an array containing the TD contents.

Upvotes: 1

Related Questions