让html自动具有ajax,AJAX自动加载HTML5的部分

我一直工作在一个网站,自动负载上滚动的新内容从MySQL数据库中。 但问题是,即使滚动可以忽略不计,它也会加载新内容。我的意思是它在滚动时加载新内容,而不是在页面结束时加载。 可滚动部分位于静态框架内。AJAX自动加载HTML5的部分

jQuery代码:

$(document).ready(function() {

var track_load = 0; //total loaded record group(s)

var loading = false; //to prevents multipal ajax loads

var total_groups = <?php echo $total_groups; ?>; //total record group(s)

$('#results').load("autoload_process.php", {'group_no':track_load}, function() {track_load++;}); //load first group

$("#frames").scroll(function() { //detect page scroll

if($(window).scrollTop() + $(window).height() == $(document).height()) //user scrolled to bottom of the page?

{

if(track_load <= total_groups && loading==false) //there's more data to load

{

loading = true; //prevent further ajax loading

$('.animation_image').show(); //show loading image

//load data from the server using a HTTP POST request

$.post('autoload_process.php',{'group_no': track_load}, function(data){

$("#results").append(data); //append received data into the element

//hide loading image

$('.animation_image').hide(); //hide loading image once data is received

track_load++; //loaded group increment

loading = false;

}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?

alert(thrownError); //alert with HTTP error

$('.animation_image').hide(); //hide loading image

loading = false;

});

}

}

});

});

伙计们,请帮我一下吧。可能有'

$(window).scrollTop()+ $(window).height()== $(document).height()`这个部分存在某种问题。

我要跟踪的部分不是窗口的滚动。

+0

建议你使用这个插件:http://imakewebthings.com/jquery-waypoints/ –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值