简体   繁体   English

PHP AJAX分页将项目加载到多个容器中

[英]PHP AJAX pagination load items into multiple containers

I would like to create a simple "load more" button but I have a three column design which makes it a little comlicated because I only want to load the items into their parent element. 我想创建一个简单的“加载更多”按钮,但是我采用了三列设计,这使其有点复杂,因为我只想将项目加载到其父元素中。 I used infinite ajax scroll on other sites but in this case it doesn't work or it works if I set the items to load to the parent element. 我在其他站点上使用了无限ajax滚动,但是在这种情况下,它不起作用,或者如果我将项目设置为加载到父元素,则它可以工作。

my html layout looks like this: 我的html布局看起来像这样:

<div id="container">
  <div class="firstcol column">
    <article class="item">Content</article>
    <article class="item">Content</article>
    <article class="item">Content</article>
  </div>
  <div class="secondcol column">
    <article class="item">Content</article>
    <article class="item">Content</article>
    <article class="item">Content</article>
  </div>
  <div class="thirdcol column">
    <article class="item">Content</article>
    <article class="item">Content</article>
    <article class="item">Content</article>
  </div>
</div>
<div class="padination">
  <a class="next" href="http://example.com/?start=10">load more</a>
</div> 

So, if its possible I want to load only the elements into its appropriate column. 因此,如果可能的话,我只想将元素加载到其适当的列中。 Is there a solution for this or do I need to load the column divs and figure out a way with css to make it look nice? 有解决方案吗?还是我需要加载列div并找出使用CSS的方法使其看起来更好? Oh almost forgot if I don't have any JS/AJAX than the load more link works like any other php-mysql pagination (for example like on a joomla blog layout) and the data returned and printed is the same as the html code above. 哦,差点忘了,如果我没有任何JS / AJAX,那么加载更多的链接就可以像其他任何php-mysql分页一样工作(例如,在joomla博客布局上),并且返回和打印的数据与上面的html代码相同。

I hope my question is clear. 希望我的问题清楚。

If your AJAX call is returning HTML, you can set that into a jQuery object then retrieve specific parts of it. 如果您的AJAX调用返回的是HTML,则可以将其设置为jQuery对象,然后检索其中的特定部分。 This is untested, but in principle it should work: 这未经测试,但原则上应该可以:

"success" : function(data) {
    //add articles from first col of return html
    var $html = $(data);
    $html.find("div.firstcol article").appendTo("div#container div.firstcol");
    $html.find("div.secondcol article").appendTo("div#container div.secondcol");
    $html.find("div.thirdcol article").appendTo("div#container div.thirdcol");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM