$.ajaxSetup({
contentType:'application/x-www-form-urlencoded; charset=UTF-8'
});
var FrameNum = 2;
var tempclienth;
var tempscrollh;
var tempscrollt;
var num = 0;
$(document).ready(function(){
$(window).scroll(function () {
var clienth = document.documentElement.clientHeight;
var scrollh = document.documentElement.scrollHeight;
var scrollt = document.documentElement.scrollTop + document.body.scrollTop;
var stopflg =$('#stopFlg').val();
var onflg = true;
if (tempclienth == clienth && tempscrollh == scrollh && tempscrollt == scrollt) {
return;
}
if (clienth + scrollt +500> scrollh && onflg && stopflg == 1 ) {
tempclienth = clienth;
tempscrollh = scrollh;
tempscrollt = scrollt;
onflg = false;
var categoryId = $('#categoryId').val();
if (categoryId == null || categoryId == '') {
categoryId = $('#optionCateId').val();
}
$.ajax({
type : "POST",
url: 'goods/getFinalGoods.ct?FrameNum='+FrameNum,
data : {'folderId':$('#folderId').val(),'color':$('#color').val(),'leave':$('#leave').val(),
'categoryId':categoryId,'pagination.currentPage':$("#currentPage").val()},
dataType: "json",
success: function(data){
var totalSize = data.yourObject.totalSize;
var pageSize = data.yourObject.pageSize;
var currentPage = data.yourObject.currentPage;
var frameSize = data.yourObject.frameSize;
temp = totalSize - (pageSize*currentPage);
if (temp>=0) {
num = pageSize/frameSize;
} else {
num = Math.ceil((totalSize - pageSize*(currentPage-1))/frameSize);
}
$('#stopFlg').val(data.yourObject.hasNextGroup);
var enshrines=getEnshrines();
$(data.yourObject.data).each(function(index,v){
var text=showGoodsHtml(v,enshrines);
$('#image_wall').append(text);
myFn();
});
FrameNum ++;
if (num < FrameNum) {
stopflg = $('#stopFlg').val(0);
$('#pager').show();
}
onflg = true;
},
error: function(){
alert('查询失败!');
onflg = true;
}
});
}
});
});此时是全局变量 这个ajax瀑布流很容易就会连续发送两次相同请求 也就是onflg有时会失效 而且比较严重 但是将onflg改为全局变量便一点事也没有了 难道全局变量和局部变量的值改变时间也不一样吗 不是应该只有作用域不一样么
contentType:'application/x-www-form-urlencoded; charset=UTF-8'
});
var FrameNum = 2;
var tempclienth;
var tempscrollh;
var tempscrollt;
var num = 0;
$(document).ready(function(){
$(window).scroll(function () {
var clienth = document.documentElement.clientHeight;
var scrollh = document.documentElement.scrollHeight;
var scrollt = document.documentElement.scrollTop + document.body.scrollTop;
var stopflg =$('#stopFlg').val();
var onflg = true;
if (tempclienth == clienth && tempscrollh == scrollh && tempscrollt == scrollt) {
return;
}
if (clienth + scrollt +500> scrollh && onflg && stopflg == 1 ) {
tempclienth = clienth;
tempscrollh = scrollh;
tempscrollt = scrollt;
onflg = false;
var categoryId = $('#categoryId').val();
if (categoryId == null || categoryId == '') {
categoryId = $('#optionCateId').val();
}
$.ajax({
type : "POST",
url: 'goods/getFinalGoods.ct?FrameNum='+FrameNum,
data : {'folderId':$('#folderId').val(),'color':$('#color').val(),'leave':$('#leave').val(),
'categoryId':categoryId,'pagination.currentPage':$("#currentPage").val()},
dataType: "json",
success: function(data){
var totalSize = data.yourObject.totalSize;
var pageSize = data.yourObject.pageSize;
var currentPage = data.yourObject.currentPage;
var frameSize = data.yourObject.frameSize;
temp = totalSize - (pageSize*currentPage);
if (temp>=0) {
num = pageSize/frameSize;
} else {
num = Math.ceil((totalSize - pageSize*(currentPage-1))/frameSize);
}
$('#stopFlg').val(data.yourObject.hasNextGroup);
var enshrines=getEnshrines();
$(data.yourObject.data).each(function(index,v){
var text=showGoodsHtml(v,enshrines);
$('#image_wall').append(text);
myFn();
});
FrameNum ++;
if (num < FrameNum) {
stopflg = $('#stopFlg').val(0);
$('#pager').show();
}
onflg = true;
},
error: function(){
alert('查询失败!');
onflg = true;
}
});
}
});
});此时是全局变量 这个ajax瀑布流很容易就会连续发送两次相同请求 也就是onflg有时会失效 而且比较严重 但是将onflg改为全局变量便一点事也没有了 难道全局变量和局部变量的值改变时间也不一样吗 不是应该只有作用域不一样么
1,你给的代码中的onflg还是局部变量吧。window.onload = function(){
var aa ="a";
alert(aa);
}
function check(){
alert("1231");
alert("aa="+aa);//这个地方时无法调用的。
}2,这个是在滚动页面的时候触发的吧?那每当滚动页面时这个就会触发一次请求,而请求的结果不管是成功还是失败,最后onflg都会被重新变成true。这个跟在每次var onflg定义这个也算是功能冲突了吧。