我使用jquery/php/mysql在页面上加载twitter搜索结果,但仅限于前20个搜索结果。
当用户滚动页面并点击页面底部时,将加载并显示另外20个结果。
我已经实施了投票系统,所以这些特定的推特可以上下投票。
但是,当加载滚动结果时,此功能将停止对Ajax加载结果的工作,但继续对前20个结果进行工作。
以下是获取滚动新结果的jquery:
j(window).scroll(function(){
if (j(window).scrollTop() == j(document).height() - j(window).height()){
j.ajax({
url: "older.php?oldest="+oldestName+"",
cache: false,
success: function(html){
j(".older").html(html);
j('.tweets ul li').removeClass( 'last_item' );
j('.older ul > *').clone().hide().appendTo('.tweets ul').slideDown();
}
})
}
});
以及设置投票的jquery:
$("a.vote_up").click(function(){
//get the id
the_id = $(this).attr('id');
// show the spinner
$(this).parent().html("<img src='images/spinner.gif'/>");
//fadeout the vote-count
$("span#votes_count"+the_id).fadeOut("fast");
//the main ajax request
$.ajax({
type: "POST",
data: "action=vote_up&id="+$(this).attr("id"),
url: "vote.php",
success: function(msg) {
$("span#votes_count"+the_id).html(msg);
//fadein the vote count
$("span#votes_count"+the_id).fadeIn();
//remove the spinner
$("span#vote_buttons"+the_id).remove();
}
});
});
HTML标记:
<li id='1283009589'>
<a class='imglink' target='_blank' href='link'>
<img src='link'alt='howtomoodle' title='howtomoodle' />
</a>
<a class='userlink' target='_blank' href='http://twitter.com/jim' alt='jim' title='jim'>jim</a>
Screenpresso - free screen capture software http://post.ly/uFxt #moodle || 28-08-2010 16:33
<span class='votes_count' id='votes_count22361731118'>Votes:0</span>
<span class='vote_buttons' id='vote_buttons22361731118'>
<a href='javascript:;' class='vote_up' id='22361731118'></a>
<a href='javascript:;' class='vote_down' id='22361731118'></a>
</span>
</li>
有人知道为什么要加载旧的结果吗?他们不允许单击voteup和votedown按钮,或者至少不允许单击.click事件。