栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

客户端分页记录

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

客户端分页记录

如我的评论所述。

您可以执行以下操作:

$(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,并且仅发送回结果表。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/569096.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号