数据表和jQuery $ .post [英] Datatables and jQuery $.post

查看:109
本文介绍了数据表和jQuery $ .post的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页中有一个数据表表,其中有一页以上的分页数据.根据数据表给出的示例,我使用以下javascript/jQuery来提交表单:

I have a datatables table in my webpage with more than one page of paginated data in it. Per the example given by datatables, I use the following javascript/jQuery to submit the form:

<script>
var oTable;
$(document).ready(function() {
    $('#form').submit( function() {
        var sData = oTable.$('input').serialize();
        $.post('', sData); // WORKS
        // $.post('', sData, $('body').html(data)); // DOES NOT WORK
        return false;
    } );

    oTable = $('#meters').dataTable();
} );
</script>

当我通过$.post('', sData);发布时,我的所有表行都被发布了.当我发布$.post('', sData, $('body').html(data));时,仅表的可见页面的行被发布.为什么?

When I post via $.post('', sData);, all of my table rows are posted. When I post with $.post('', sData, $('body').html(data));, only the rows of the visible page of the table are posted. Why?

我对jQuery很陌生-也许我缺少一些东西...

I'm fairly new to jQuery -- perhaps I am missing something...

这是我用来初始化表格的代码:

Here is the code I use to initialize the table:

<script>    

/* Create an array with the values of all the input boxes in a column */
$.fn.dataTableExt.afnSortData['dom-text'] = function  ( oSettings, iColumn )
{
    var aData = [];
    $( 'td:eq('+iColumn+') input:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
        aData.push( this.value );
    } );
    return aData;
}

/* Create an array with the values of all the select options in a column */
$.fn.dataTableExt.afnSortData['dom-select'] = function  ( oSettings, iColumn )
{
    var aData = [];
    $( 'td:eq('+iColumn+') select:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
        aData.push( $(this).val() );
    } );
    return aData;
}

/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function  ( oSettings, iColumn )
{
    var aData = [];
    $( 'td:eq('+iColumn+') input:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
        aData.push( this.checked==true ? "1" : "0" );
    } );
    return aData;
}

    $(document).ready(function() {
        $('#meters').dataTable(
            {
                "aoColumns": [
                    { "sSortDataType": "dom-text" },
                    { "sSortDataType": "dom-select" },
                    { "sSortDataType": "dom-checkbox" },
                ],
                "aoColumnDefs": [
                    { 
                        "aTargets":     ["vbNoSearchSort"],
                        "bSearchable":  false,
                        "bSortable":    false
                    }
                ],
                "bProcessing"   :true,
                "bStateSave"    :true,
                "sPaginationType": "full_numbers"
            }
        );
    } );
</script>

推荐答案

,因为它需要是闭包或对函数的引用.

because it needs to be a closure or a reference to a function.

$.post('', sData, function(data){$('body').html(data); }); 

function callback(data) {
   $('body').html(data);
}
$.post('', sData, callback); 

这篇关于数据表和jQuery $ .post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆