I'm trying to do a form submit (POST) with some parameters and based on the parameters I want to populate my datatable. But I'm not very good with Javascript (My language is Java), so I'm trying to do it with an Ajax call. But it won't work for me. Everything works for me, except doing a POST with parameters to the servlet. The datatable always populate automatically, but it should populate after the form submit.
Does someone know an example of my case? I read a lot of form posts here and tutorials, but none of this case (?).
My code is now as follows, this works for me. Except I can't sort or search anymore in this table. What is missing?
Thank you.
Does someone know an example of my case? I read a lot of form posts here and tutorials, but none of this case (?).
My code is now as follows, this works for me. Except I can't sort or search anymore in this table. What is missing?
Thank you.
<script type="text/javascript" language="javascript" src="/global/js/jquery-1.9.1.min.js"></script> <script type="text/javascript" language="javascript" src="/global/js/jquery.dataTables.min.js"></script> <form name="myform" id="myform" action="" method="POST"> <label for="season">Season:</label> <input type="text" name="season" id="season" value=""/> <br /> <label for="type">Type:</label> <input type="text" name="type" id="type" value=""/> <br/> <input type="button" id="btnSubmit" name="btnSubmit" value="Search"> </form> <table class="display" id="example"> <thead> <tr> <th>Name</th> <th>NationId</th> <th>RegionId</th> <th>Attendance</th> </tr> </thead> <tbody> <!-- data goes here --> </tbody> </table> <script> $("#btnSubmit").click( function() { var formData = "season=" + $("input#season").val() + "&type=" + $("input#type").val(); $('#example').dataTable( { "bJQueryUI": true, "bProcessing": true, "bDestroy": true, "sAjaxSource": "/servlets/service/competitions/", "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) { oSettings.jqXHR = ${esc.d}.ajax( { "dataType": 'json', "type": "POST", "url": sSource, "data": formData, "success": fnCallback } ); } } ); } ); </script>