客户端分页记录

客户端分页记录,第1张

客户端分页记录

如我的评论所述。

您可以执行以下 *** 作:

$(document).ready(function(){    $('.paginate').live('click', function(e)    {        e.preventDefault();        var btnPage = $(this);        $.ajax(        { url : btnPage.attr('href'), success : function(resp) {     // replace current results with new results.     $('#project_section').html(resp); }, error : function() {     window.location.href = btnPage.attr('href'); }        });    });});

上面的代码将复制您单击每个分页链接的位置。

我接下来建议做的是将生成“结果”列表的PHP代码和HTML分离到一个单独的文件中。

这样,在显示结果的页面上,您可以简单地使用

include('path-to-results-file.php');
适用于非ajax请求的内容,然后可以执行以下 *** 作:

Process.php

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){    include('path-to-results-file.php');    die();}

上面的代码将检测是否已发出ajax请求,如果已发出,则不显示整个页面(包括结果),而仅显示结果和分页。

更新以包含更好的解释

下面是我的意思的一个非常简单的例子。

当前process.php

    <?    // currently contains all of the pre required    // to query the database etc.?><html><head>...</head><body>    <!-- header content -->    <table>    <?        // currently contains all of the pre required to display        // the results table and pagination links.    ?>    </table>    <!-- footer content --></body></html>

新的process.php

<?    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')    {        include('path-to-results-file.php');        die();    }?><html><head>...</head><body>    <!-- header content -->    <? include('path-to-results-file.php'); ?>    <!-- footer content --></body></html>

新的path-to-results-file.php

<?    // currently contains all of the pre required    // to query the database etc.?><table><?    // currently contains all of the pre required to display    // the results table and pagination links.?></table>

现在…当您

process.php
通过浏览器正常访问或禁用javascript时。它将像现在没有Javascript一样简单地工作。

当您转到

process.php
然后单击其中一个分页链接(已启用javascript)时,
process.php
将检测到您正在使用Ajax,并且仅发送回结果表。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5560373.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存