DataTables Post Ajax Method

DataTables Post Ajax Method

ravashjalilravashjalil Posts: 1Questions: 1Answers: 0
edited March 2017 in Free community support

Hello, I'm new to Jquery and just getting use to datatables.

Right now I'm trying to create a button that will send back all table data back to the server. Right now im doing it via function that collects the table elements and then passes it through via ajax however its a bit messy. I just came across the POST data
section in which this example was displayed.


$(document).ready(function() { $('#example').DataTable( { "processing": true, "serverSide": true, "ajax": { "url": "scripts/post.php", "type": "POST" }, "columns": [ { "data": "first_name" }, { "data": "last_name" }, { "data": "position" }, { "data": "office" }, { "data": "start_date" }, { "data": "salary" } ] } ); } );

Can this snippet be used for the approach im trying to take? So that when I click a submit button this function is loaded and the data is sent back?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,170Questions: 92Answers: 436

    Are you using PHP / MySQL or .NET on the server side? if so I can warmly recommend to get Editor. Editor will handle it all for you. The license is dirt cheap and it is a great product. I am not affiliated with or sponsored by SpryMedia. This is just my personal opinion ...

  • allanallan Posts: 64,899Questions: 1Answers: 10,747 Site admin
    Answer ✓

    @rf1234 - Cheque is in the post ;-)

    @ravashjalil - Drop the "serverSide": true, option. serverSide enables server-side processing, which you don't want if you are returning all of the data.

    So that when I click a submit button this function is loaded and the data is sent back?

    Sure - have the event handler for your button call the ajax.reload() method. You can also use ajax.data as a function to submit data to the server on each request (for example form fields).

    Allan

This discussion has been closed.