0

I m using jquery datatables first time, so now i done table like thisClick to view Image

everything works perfectly. now i m using this below javascript code

    $(document).ready(function() {
        $('#example').dataTable( 
        {
            "pageLength": 50,
            'sDom': 'l' ,
        } );
        $('#example tfoot th').each( function () 
        {
            var title = $('#example thead th').eq( $(this).index() ).text();
            $(this).html( '<input type="text" style="width:100%;" id="munna_'+title+'" placeholder="Search '+title+'" />' );
        });


        var table = $('#example').DataTable();
        table.columns().every( function () 
         {
        var that = this;
        $( 'input', this.footer() ).on( 'keyup change', function () {
        that
        .search( this.value )
        .draw();
        });
        });


$('#munna_button').click( function()
   {
         var data = table.$('input, select').serialize();
        alert(JSON.stringify(data))
        return false;
    });
});

now this code returns value like this in rate_14=67&rate_15=87&rate_67=88 etc..,

now i dont have idea how to store this on SUBMIT. normally on submit i get $_POST['name'] like this, now please some one hlep me from this.

Munna Babu
  • 5,496
  • 6
  • 29
  • 44
  • 1
    you need to call ajax. add ajax url where you need to accept post request in php. `$.ajax({url:"", type:"POST", data:"serializeData"});` – mohit Apr 27 '15 at 09:20
  • 1
    @Munna try $.ajax() visit http://api.jquery.com/jquery.ajax/ – Shelim Apr 27 '15 at 09:22
  • but there is possible to enter more than 20 values so when i do in ajax it may take more time thats why i am asking on SUBMIT – Munna Babu Apr 27 '15 at 09:22

2 Answers2

1

Simply use ajax to send the information:

$('#munna_button').click( function(){
      var data = table.$('input, select').serialize();
      $.post('url_link_here', data, function(returnData){
        //success -- do stuff with returnData if there is any

      }).fail(function(){
        //failed

      });
 });
kemicofa ghost
  • 16,349
  • 8
  • 82
  • 131
  • there will be more then 100 records so the rate_14=67&rate_15=87&rate_67=88... will go so long ?? it wont affect and make slow ? – Munna Babu Apr 27 '15 at 09:25
  • 1
    @Munna why would it be slow? Whether you actually submit all the information and refresh the page or send it via ajax your internet speed and server capacity won't change. It'll be the same. – kemicofa ghost Apr 27 '15 at 09:26
1

You could store the serialized data into a hidden variable added to form. and in java script use some like this to save the value in hidden field

$('#serialize_data').val(JSON.stringify(data));

After the form is submitted, you will find the value in

$_POST['serialize_data']

If you don't want to submit the form , you can use ajax to send data to .php script I hope this will help you

vasilenicusor
  • 2,023
  • 1
  • 21
  • 37