weixin_33711641 2011-10-02 20:02 采纳率: 0%
浏览 32

使用jQuery + AJAX + XML“加载更多”

I'm making a website to show a lot of documents (PDFs and JPGs) in one page, and I'm worried about page load times and server load because there are a lot of files. I'm storing the file data in an XML file, and am retrieving the data with jQuery and AJAX.

jQuery:

$(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "scripts/imagenes.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('imagen').each(function() {
                var path = $(this).find('path').text();
                var img = $(this).find('img').text();
                var thumb = $(this).find('thumb').text();
                $('<a rel="lightbox" href="'+path+img+'">').html('<img src="' + path + thumb + '" /></a>').appendTo(".item_aesmr_img_hola");
            });
        }
    });
});

XML:

<?xml version="1.0" encoding="UTF-8"?>
<instituciones>
  <aesmr>
    <carnets>
      <imagen>
        <path>docs/aesmr/carnets/</path>
        <img>aesmr-carnet-016b.jpg</img>
        <thumb>thumbs/aesmr-carnet-016b.jpg</thumb>
      </imagen>
      <imagen>
        <path>docs/aesmr/carnets/</path>
        <img>aesmr-carnet-025b.jpg</img>
        <thumb>thumbs/aesmr-carnet-025b.jpg</thumb>
      </imagen>
      ...and so on...
    </carnets>
  </aesmr>
</instituciones>

I thought it would be a nice idea to use the typical Load more... button, just to let the user load the images as and when they want, with an increment of 20 images at a time. I load the thumbs with the full image is loaded when the thumbnail is clicked.

Is there a way to just load the first 20 results and then use the button to show 20 more?

  • 写回答

1条回答 默认 最新

  • weixin_33720186 2011-10-02 20:28
    关注

    one option would be to add counter in the "each" block. so that when you reach 20, you terminate the execution of the script.

    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题