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.

3
  • 1
    you need to call ajax. add ajax url where you need to accept post request in php. $.ajax({url:"", type:"POST", data:"serializeData"}); Commented Apr 27, 2015 at 9:20
  • 1
    @Munna try $.ajax() visit api.jquery.com/jquery.ajax Commented Apr 27, 2015 at 9: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 Commented Apr 27, 2015 at 9:22

2 Answers 2

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

      });
 });
Sign up to request clarification or add additional context in comments.

2 Comments

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 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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.