weixin_33738578 2014-06-22 13:23 采纳率: 0%
浏览 51

迭代Ajax负载选择器

I am trying to create an 'infinite scroll' using Ajax (or rather specifically using Jquery's .load function), the function fires perfectly and in the instances where it has worked it spits out a comical amount of articles, so I figured that I should create a unique, iterating div (id1,id2,id3 etc) but when using an iterating selector to load the Ajax content into unique div ids, by iterating it, it .load fails or doesn't fire.

var busy = false;
var i = 1;
var x = 0;

function content(){
if($(document).height() * 0.7 < $(document).scrollTop() && !busy) {
var offset = i++ * 6;
$("#expand").after("<section id='expand" + x++ + "' class='gridWrapper'></section>");

$("#expand" + x).load("/ajaxcontent/", {section: 'articles', category: '', limit: '6', offset: offset, form: 'grid', action: 'article'}, function(){
busy = true;
}); 
    x++                                     
} else {
   busy = false;
}
}   

window.onscroll = content;
document.ready = content; 

My question is how do I get the selector $("#expand" + x) to work correctly? In the variations (for loops, while loops, .each) I have tried where it does output articles it goes utterly bananas and essentially regurgitates all articles. Any help would be hugely appreciated!

(As it is a an Ajax load, I don't think that I can create a JsFiddle)

  • 写回答

1条回答 默认 最新

  • 乱世@小熊 2014-06-22 13:27
    关注

    This is working

    $('#expand' + x)
    

    try to remove the ++ in this line

    $("#expand").after("<section id='expand" + x++ + "' class='gridWrapper'></section>");
    

    to

    $("#expand").after("<section id='expand" + x + "' class='gridWrapper'></section>");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题