Javascript 为同一事件的每次事件追加数据
每次用户Javascript 为同一事件的每次事件追加数据,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,每次用户滚动到窗口底部时,我都会使用ajax添加一些php文件 $(window).scroll(function(){ if($(window).scrollTop() + $(window).height() > $(document).height() - 100){ $(window).unbind('scroll'); // Function to append php files using ajax } }) 我想识别用户下次滚动到页面底部并
滚动到窗口底部时,我都会使用ajax添加一些php文件
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 100){
$(window).unbind('scroll');
// Function to append php files using ajax
}
})
我想识别用户下次滚动到页面底部并附加一些其他php文件的时间,但如何找出下一个(1个或多个)滚动到页面底部的事件
Example: First scroll to bottom: Append 1.php 2.php
second scroll to bottom: append 3.php 4.php
third scroll to bottom: append 5.php 6.php
4th scroll to bottom: show footer
我不需要无限滚动插件。因为这里没有页脚的概念。您需要维护一个计数器变量,用于计算您发出的请求数量。然后可以将其传递给服务器,服务器将返回所需的信息。大概是这样的:
var requestCount = 0;
$(window).scroll(function(){
if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
$(window).unbind('scroll');
// Function to append php files using ajax
requestCount++;
if (requestCount < 4) {
$.ajax({
url: 'foo.php',
data: { page: requestCount },
success: function() {
// append your items
}
}
}
else {
// show footer
}
}
})
var requestCount=0;
$(窗口)。滚动(函数(){
if($(窗口).scrollTop()+$(窗口).height()>$(文档).height()-100){
$(窗口)。解除绑定(“滚动”);
//函数使用ajax附加php文件
requestCount++;
如果(请求计数<4){
$.ajax({
url:'foo.php',
数据:{page:requestCount},
成功:函数(){
//附加您的项目
}
}
}
否则{
//显示页脚
}
}
})
在PHP中,您需要获取页面
变量并返回相关项。您需要维护一个计数器变量,用于计算您发出的请求数量。然后,您可以将其传递给服务器,服务器将返回所需信息。类似如下:
var requestCount = 0;
$(window).scroll(function(){
if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
$(window).unbind('scroll');
// Function to append php files using ajax
requestCount++;
if (requestCount < 4) {
$.ajax({
url: 'foo.php',
data: { page: requestCount },
success: function() {
// append your items
}
}
}
else {
// show footer
}
}
})
var count = 1;
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 100){
$(window).unbind('scroll');
if(count<4)
// Function to append php files using ajax
call_your_ajax_with_url(count+'.php');
call_your_ajax_with_url(count+1 +'.php');
count+=1;
else showFooter();
}
});
var requestCount=0;
$(窗口)。滚动(函数(){
if($(窗口).scrollTop()+$(窗口).height()>$(文档).height()-100){
$(窗口)。解除绑定(“滚动”);
//函数使用ajax附加php文件
requestCount++;
如果(请求计数<4){
$.ajax({
url:'foo.php',
数据:{page:requestCount},
成功:函数(){
//附加您的项目
}
}
}
否则{
//显示页脚
}
}
})
在PHP中,您需要获取页面
变量并返回相关项。var count=1;
var count = 1;
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 100){
$(window).unbind('scroll');
if(count<4)
// Function to append php files using ajax
call_your_ajax_with_url(count+'.php');
call_your_ajax_with_url(count+1 +'.php');
count+=1;
else showFooter();
}
});
$(窗口)。滚动(函数(){
if($(窗口).scrollTop()+$(窗口).height()>$(文档).height()-100){
$(窗口)。解除绑定(“滚动”);
如果(计数<代码>变量计数=1;
$(窗口)。滚动(函数(){
if($(窗口).scrollTop()+$(窗口).height()>$(文档).height()-100){
$(窗口)。解除绑定(“滚动”);
如果(countWhy not simply count it…?我做了它不能正常工作…我有一个if语句来执行一个block为什么不简单地计算它…?我做了它不能正常工作…我有一个if语句来执行一个block it soes不能解决我的问题,我接受它只是为了减少答案soes不能解决我的问题,我接受它只是为了减少e答案