Newbe: DataTables with form elements example; alert to url

Newbe: DataTables with form elements example; alert to url

jsailjsail Posts: 4Questions: 1Answers: 0
edited April 2014 in DataTables
Your example 'DataTables with form elements' works perfect. Also hidden values are printed in the Alert.

But how can I use that var 'sData' to use it as GET or POST submit?

When I try it in the form, the hidden data is not included.

Thank you for your help.

Joseph

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You'd use a bit of Ajax: https://api.jquery.com/jQuery.ajax/

    Allan
  • jsailjsail Posts: 4Questions: 1Answers: 0
    Thank you Allan,

    as a Newbe, I would prefer to keep everythin so simple as possible...

    Is there a easy way, I could use the variable sData in the body of the document?

    Joseph

    [code]$('#form').submit( function() {
    var sData = oTable.$('input').serialize();
    alert( "The following data would have been submitted to the server: \n\n"+sData );
    return false;
    } );
    ...

    <?php echo "sData=".sData."
    ";
    ...
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you want to use the elements as part of the submit you have two options:

    1. Move the input elements into the document (use fnGetNodes to get all row nodes from the table)

    2. Copy the elements and put them into the document with their values set to match the original.

    Allan
  • jsailjsail Posts: 4Questions: 1Answers: 0

    Hi Allan,

    I tried with the ajax to submit post the data. Finally it works, but it is just glued together. The code originally comes from the example "form.html".

    Thank you for your help.
    Joseph

    $(document).ready(function() {
        $('#form').submit( function() {
            var sData = oTable.$('input').serialize();
    
            //ajax insert start
            //ajax submit; success output?
            $.ajax({
              type: "POST",
              url: "selection.php",
              data: sData,
              success: function() {
                "data submit ok"
              }
            });
            //ajax insert end
    
            alert( "The following data would have been submitted to the server: \n\n"+sData );
            return false;
        } );
        
        oTable = $('#example').dataTable();
    } );
    
This discussion has been closed.