【问题标题】:I need to add pagination to my ajax page results我需要在我的 ajax 页面结果中添加分页
【发布时间】:2012-06-26 13:01:37
【问题描述】:

我已经为我的城市标签创建了 ajax 代码来显示来自 ajax 的各个城市数据。

我使用了以下代码:

function showBrandData(str)
    document.getElementById("dvloader").style.display = 'block';                                
    jQuery('#txtDisplayBrands').slideDown("slow");

    if (str=="")
    {
        document.getElementById("txtDisplayBrands").innerHTML="";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("dvloader").style.display = 'none';
            document.getElementById("txtDisplayBrands").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","http://localhost/demostore/getBrandData.php?q="+str+"&page=1",true);
    xmlhttp.send();
}

以下是我加载 ajax 内容的 div

  <!-- div to display brands products -->
    <div id="txtDisplayBrands"></div>

现在我使用以下 jquery 插件对我的项目进行分页 http://cssglobe.com/post/9801/easy-paginate-jquery-plugin-for-pagination

但是当我在我的 ajax 响应中使用它时,分页不起作用。

你能帮我解决我做错的地方吗?

感谢和问候

【问题讨论】:

  • 在您的代码中使用 [$.ajax]()api.jquery.com/jQuery.ajax 其 jquery 版本的 xmlhttp 请求,如果您仍有问题,请在之后更新问题 :)
  • 您可能会发现编写 10 行代码来对自己进行 ajax 分页比依赖其他人的代码更容易。这也可能使我们更容易为您提供帮助。

标签: php jquery ajax


【解决方案1】:

该站点的默认代码:

<script type="text/javascript">

  jQuery(function($){ 
  $('ul#items').easyPaginate();
  }); 

</script>

在页面加载时被调用。之后您的 ajax 调用将被执行,因此您需要在 ajax 调用中加载的元素上调用分页代码。

考虑在 if 语句中添加它 if (xmlhttp.readyState==4 && xmlhttp.status==200)

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多