retreave data from selected rows and send this data in Json to the server

retreave data from selected rows and send this data in Json to the server

Hello!
I have a " json is not defined" from my browser when I click on the button bind to the function createSoftwareUpdateScript...
I want to retreave the data from selected rows and send this data in Json to the server.


function createSoftwareUpdateScript() {

                var table = $('#myTable').DataTable();
                var selectedData = table.rows( { selected: true } ).data().toArray();

                $.ajax({
                    type: 'POST',
                    url: 'http://localhost:8080//RedlogServer3/Servlet',
                    dataType: 'json',
                    data: {json: JSON.stringify(selectedData)},
                    success: function (data) {
                        alert('success insert' + json);
                    }
                });
            };

Answers

  • kthorngrenkthorngren Posts: 21,364Questions: 26Answers: 4,956

    In your success function you are passing the parameter data but using the variable json. Maybe you meant somethign like this:

            success: function (data) {
                alert('success insert' + data);
            }
    

    Kevin

  • guillaume.lheureux.son@gmail.comguillaume.lheureux.son@gmail.com Posts: 15Questions: 6Answers: 1

    with my first code I achieved well to retrieve all the data. But what I want now is to retrieve just the selected one..

    My first code:


                function saveData() {
                    var table = $('#myTable').DataTable();
                    var tableData = table.rows().data().toArray();
    
                    $.ajax({
                        type: 'POST',
                        url: 'http://localhost:8080//RedlogServer3/AddLicenceServlet',
                        dataType: 'json',
                        data: {json: JSON.stringify(tableData)},
                        success: function (data) {
                            alert(json);
                            console.log(json);
                        }
                    });
                }
                ;
    

    Compare to this code (that is working) I just add "{ selected: true }" that I thaught would filter the data with only the selected rows... But it's not working :(

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    table.rows( {selected: true} ).data().toArray();
    

    will give you an array of the data from the rows which have been selected with the Select extension. If that isn't working for you, we'd need a link to an example showing the issue.

    Allan

This discussion has been closed.