开发者

Datatables submit form serverside data

For those of you that use the Datatables js plug开发者_Go百科in, how can I create this example with server side data?

The example uses data that is hardcoded in the HTML.


You would basically do the following:

  • Serialize the form data (using jquery serialize as the example shows)
  • Submit said data to your form handling scrip (php etc)

They already provide the jquery serialize code so I won't show that, however the jQuery AJAX function will be needed (at the least):

$.ajax({
   type: "POST",
   url: "some.php",
   data: YOUR-SERIALIZED-DATA-HERE,
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });

And on your Server side PHP file you just grab the correct form array and parse your values ($_POST).


I had the same problem and didn't want to do an ajax save, so I did this:

var table = $("#mytable").datatable();

$("#myform").submit(function () {
    var hiddenArea = $("<div></div").hide().appendTo("#myform");
    table.$('input:hidden').detach().appendTo(hiddenArea);

    // Prevent original submit and resubmit, so the newly added controls are
    // taken into account
    this.submit();
    return false;
});

The idea is that I take all the inputs that are currently not in the dom and move them inside a hidden container.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜