87,909
社区成员
发帖
与我相关
我的任务
分享
|-------------------|
| |
| 主页面部分 |
| |
|___________________|
______________________
-------- |
| DIV1 | |
-------- |--------
|| DIV2 |
-------- |--------
| DIV3 | |
-------- |--------
|| DIV4 |
|--------
$('div').each(function(){
if(!$(this).contents().length){//用each,判断是否DIV里已有内容?避免重复加载。
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height() + $('#footer').height()){
//判断鼠标是否滚动到页面底部,这里还需要去除一个 div#footer 页脚的高度
var toRequest=new Array("div1", "div2", "div3", "div4");//把4个DIV存为数组
$.ajax({
url: "ajax.php" ,
dataType: "html",
type: 'POST',
data: toRequest[index]+'=1',//分别发送各自的数据到ajax.php,调回数据
success: function(data){
$("#"+toRequest[index]).html(data);//返回数据到各自的DIV里
if (index+1<toRequest.length) {
doRequest(index+1);
//ajax返回成功后,index+1,进入数组下一个
}
}
});
});
});
});
$('div').each(function(){
if(!$(this).contents().length){//用each,判断是否DIV里已有内容?避免重复加载。
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height() + $('#footer').height()){
//判断鼠标是否滚动到页面底部,这里还需要去除一个 div#footer 页脚的高度
var toRequest=new Array("div1", "div2", "div3", "div4");//把4个DIV存为数组
$.ajax({
url: "ajax.php" ,
dataType: "html",
type: 'POST',
data: $("#div1"),//分别发送各自的数据到ajax.php,调回数据
success: function(data){
$("#div1").html(data);//返回数据到各自的DIV里
if (data!="") { //呵呵,你在success里在加载第二个DIV,写的笨了点,不过应该是这个意思
$.ajax({
url: "ajax.php" ,
dataType: "html",
type: 'POST',
data: $("#div2"),//分别发送各自的数据到ajax.php,调回数据
success: function(data){
$("#div2").html(data);//返回数据到各自的DIV里
if (data!="") {
...
}
}
});
}
}
});
});
});
});