0

我的表格代码是这个

<table class="table responsive-table" id="sorting-advanced">
                <thead>
                    <tr>
                        <th scope="col">Estado</th>      
                        <th scope="col" width="5%" class="align-center hide-on-mobile">Registo</th>
                        <th scope="col" width="5%">Expiração</th>
                        <th scope="col" width="5%" class="align-center hide-on-mobile">Inserção</th>
                        <th scope="col" width="10%">Dominio</th>
                        <th scope="col" width="10%" class="align-center hide-on-mobile">Titular</th>
                        <th scope="col" width="15%" class="align-center hide-on-mobile">Morada Tit.</th>
                        <th scope="col" width="10%">Email Tit.</th>
                        <th scope="col" width="15%" class="align-center hide-on-mobile">Localidade Tit.</th>
                        <th scope="col" width="15%" class="align-center hide-on-mobile">Cód. Postal</th>
                        <th scope="col" class="align-center hide-on-mobile">Nome Ent.</th>
                        <th scope="col" class="align-center hide-on-mobile">Email Ent.</th>
                        <th scope="col" class="align-center hide-on-mobile">Nome Tec.</th>
                        <th scope="col" class="align-center hide-on-mobile">Email Tec.</th>
                        <th scope="col" width="10px" >IP</th>
                        <?php if ($_SESSION['update'] == '1'){echo '<th scope="col" width=20px>Black</th>';} ?>

                    </tr>
                </thead>
                <tbody>

                </tbody>

                <tfoot>

                </tfoot>
            </table>

我的数据代码...

<script>

        // Call template init (optional, but faster if called manually)
        $.template.init();


        // Table sort - DataTables
        var table = $('#sorting-advanced'),
            tableStyled = false;

        table.dataTable({
            "iCookieDuration": 60*60*2 , 
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "http://pgcc.datasource.pt/beta/listas/whois.php",
            "sScrollX": "100%",
            "bScrollCollapse": true,
            'sPaginationType': 'full_numbers',
            'oLanguage': {
                    "sProcessing":   "A processar...",
                    "sLengthMenu":   "Mostrar _MENU_ domínios",
                    "sZeroRecords":  "Não foram encontrados resultados",
                    "sInfo":         "Lista de domínios | <button class=\"button compact green-gradient\" onClick=\"javascript: openModal();\">Adicionar</button>",     
                    "sInfoEmpty":    "Não foram encontrados resultados",
                    "sInfoFiltered": "",
                    "sInfoPostFix":  "",
                    "sSearch":       "Procurar:",
                    "sUrl":          "",
                    "oPaginate": {
                        "sFirst":    "Primeiro",
                        "sPrevious": "Anterior",
                        "sNext":     "Seguinte",
                        "sLast":     "Último"
            }
            },
            'sPaginationType': 'full_numbers',
            'fnDrawCallback': function( oSettings )
            {
                // Only run once
                if (!tableStyled)
                {
                    table.closest('.dataTables_wrapper').find('.dataTables_length select').addClass('select blue-gradient glossy').styleSelect();
                    tableStyled = true;
                }
            },

        });
            oTable = $('#sorting-advanced').dataTable();

            function fnShowHide( iCol )
            {
                /* Get the DataTables object again - this is not a recreation, just a get of the object */

                var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
                oTable.fnSetColumnVis( iCol, bVis ? false : true );

            }
            $(document).ready(function(e) {
                fnShowHide(1); 
                fnShowHide(3); 
                fnShowHide(5); 
                fnShowHide(6); 
                fnShowHide(8); 
                fnShowHide(9); 
                fnShowHide(10); 
                fnShowHide(11); 
                fnShowHide(12); 
                fnShowHide(13);
            });

    </script>


    <script>

        $('#mudar').change(function(){
            var valor = $(this).val(); 
            $.post('pesquisar.php',{valor: valor}, function(data){
            $('#pesquisa').html(data)
            });
        });

    </script>

而我得到的 JSON...

{"sEcho":0,"iTotalRecords":"2","iTotalDisplayRecords":"2","aaData":[["1","2012-08-06 17:49:05","2012-08-07","2012-08-06","nuno.pt","Nuno Almeida","Rua dos Frades","nuno_ng21@hotmail.com","Seia","1231","Gonçalo Cabral","g.cabral@datasource.pt","Datasource","teste@hotmail.com","192.168.1.0","1"],["1","2012-08-06 17:49:05","2012-08-07","2012-08-06","rumonet.pt","Nuno Almeida","Rua dos Frades","nuno_ng21@hotmail.com","Seia","1231","Gonçalo Cabral","g.cabral@datasource.pt","Datasource","teste@hotmail.com","192.168.1.0","2"]]}

但是当我加载时,表格并没有做任何事情......它只在中间出现一个白色方块,并且没有加载......

如果我将 sAjaxsource 更改为 allraedy 工作的文件,它会显示结果,但输出 JSON 格式是相等的......

Any1知道为什么会这样吗?:(

4

1 回答 1

1

我能想到的唯一一件事是,您是否将表创建的相同 sEcho 发回?来自文档

字符串 sEcho 从客户端发送的 sEcho 的未更改副本。这个参数会随着每次抽奖而改变(它基本上是一个抽奖次数)——所以实现这一点很重要。请注意,出于安全原因,强烈建议您将此参数“强制转换”为整数,以防止跨站点脚本 (XSS) 攻击。

如果你总是用相同的 json 响应,你应该省略 sEcho (并且知道省略它的危险)

于 2012-08-07T16:35:53.463 回答