weixin_33749131 2015-12-11 05:54 采纳率: 0%
浏览 16

限制来自AJAX调用的结果

I want to limit the amount of results that are being returned from this AJAX call to 5. I think I could use .slice() to do this but I'm not exactly sure what way to go about it.

$(document).ready(function() {
  $.ajax({
    type: "GET",
    url: "myurl",
    dataType: "xml",
    cache: false,
    success: parsePopular
  });
});

function parsePopular(popular) {
  $(popular).find("item").each(function() {
    $("#popularArticles").append("<h1><p class='Bold'><a href='" + $(this).find("link").text() + "'>" + $(this).find("title").text() + "</a></p></h1>");
  });
}

Any ideas would be great.

Thanks.

  • 写回答

2条回答 默认 最新

  • Lotus@ 2015-12-11 05:56
    关注

    Slice and remove

    $(popular).find('item').slice(5).remove();
    
    评论

报告相同问题?