Answer the question
In order to leave comments, you need to log in
Ajax requests on scroll event?
var load = true;
$(document).ready(function(){
$(document).on('click', '#test', function(e){
$('#load').append('Идёт загрузка...');
var page = $('#page').val();
$.ajax({
url: '/components/ajax/ajax.php',
type: 'POST',
data: JSON.stringify({ page: page }),
contentType: 'application/json; charset=UTF-8',
dataType: 'json'
})
.done(function(data) {
if (data.error == 0) {
$('#load_text_temp').html('');
console.log(data.html);
$('#page').val(parseInt(page) + 1);
}
});
return false;
});
$(window).scroll(function(){
if (!load) {
return false;
}
if($(window).scrollTop() + $(window).height() >= $(document).height() - 200) {
load = false;
$('#load').append('Идёт загрузка...');
var page = $('#page').val();
$.ajax({
url: '/components/ajax/ajax.php',
type: 'POST',
data: JSON.stringify({ page: page }),
contentType: 'application/json; charset=UTF-8',
dataType: 'json'
})
.done(function(data) {
if (data.error == 0) {
$('#load_text_temp').html('');
console.log(data.html);
load = true;
$('#page').val(parseInt(page) + 1);
}
});
return false;
}
});
});
$(document).on('click', '#test', function(e){
Запрос
});
$(window).scroll(function(){
Запрос
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question