如果我滚动如何使它成为一个延迟加载请求,多个请求将 ajax
Multiple request are going to ajax if I scroll how to make it one request for lazy loading
如果我在滚动多个请求后尝试调用 Ajax ajax 如何解决这个问题
$(window).scroll(function(){
var element = $('.MainChatList');
var scrolled = false;
if (element.scrollTop() + element.innerHeight() >= element[0].scrollHeight)
{
if(!scrolled){
scrolled = true;
var scroll = 'scroll';
loadMain(null, scroll);
scrolled = false;
}
}
});
loadMain Ajax()
$.ajax({
type : 'POST',
url : 'process.php',
data : { request : "LoadMainView", limit:limit, scroll:scroll }
}).done(function( data ) {
$(".AdminMainViewLoader").hide();
if(data)
{
var obj = JSON.parse(data);
var html_content = obj.html_content;
var scr = obj.scroll;
var data_type = obj.data_type;
if(scr == 'scroll')
{
console.log(scr);
$(".MainChatList tbody").append(html_content);
}
else
$("#MainView .MainChatData .main-two").html(html_content);
});
这里是ajax请求,收到多个请求
// taking a flag
isRequested=false;
// Now checking if not requested
if(!isRequested){
$.ajax({
type : 'POST',
url : 'process.php',
data : { request : "LoadMainView", limit:limit, scroll:scroll }
beforeSend:function(xhr){
// here we are setting isRequested to true
isRequested=true;
}
}).done(function( data ) {
$(".AdminMainViewLoader").hide();
if(data)
{
var obj = JSON.parse(data);
var html_content = obj.html_content;
var scr = obj.scroll;
var data_type = obj.data_type;
if(scr == 'scroll')
{
console.log(scr);
$(".MainChatList tbody").append(html_content);
}
else
$("#MainView .MainChatData .main-two").html(html_content);
// here we are setting isRequested to false
isRequested=false;
});
}
如果我在滚动多个请求后尝试调用 Ajax ajax 如何解决这个问题
$(window).scroll(function(){
var element = $('.MainChatList');
var scrolled = false;
if (element.scrollTop() + element.innerHeight() >= element[0].scrollHeight)
{
if(!scrolled){
scrolled = true;
var scroll = 'scroll';
loadMain(null, scroll);
scrolled = false;
}
}
});
loadMain Ajax()
$.ajax({
type : 'POST',
url : 'process.php',
data : { request : "LoadMainView", limit:limit, scroll:scroll }
}).done(function( data ) {
$(".AdminMainViewLoader").hide();
if(data)
{
var obj = JSON.parse(data);
var html_content = obj.html_content;
var scr = obj.scroll;
var data_type = obj.data_type;
if(scr == 'scroll')
{
console.log(scr);
$(".MainChatList tbody").append(html_content);
}
else
$("#MainView .MainChatData .main-two").html(html_content);
});
这里是ajax请求,收到多个请求
// taking a flag
isRequested=false;
// Now checking if not requested
if(!isRequested){
$.ajax({
type : 'POST',
url : 'process.php',
data : { request : "LoadMainView", limit:limit, scroll:scroll }
beforeSend:function(xhr){
// here we are setting isRequested to true
isRequested=true;
}
}).done(function( data ) {
$(".AdminMainViewLoader").hide();
if(data)
{
var obj = JSON.parse(data);
var html_content = obj.html_content;
var scr = obj.scroll;
var data_type = obj.data_type;
if(scr == 'scroll')
{
console.log(scr);
$(".MainChatList tbody").append(html_content);
}
else
$("#MainView .MainChatData .main-two").html(html_content);
// here we are setting isRequested to false
isRequested=false;
});
}