jQuery(document).ready(function () {
let limit = 4;
let start = 0;
let action = 'inactive';
function load_country_data(limit, start) {
jQuery.ajax({
url: "http://localhost/test/wp-admin/admin-ajax.php",
method: "POST",
data: {limit: limit, start: start, action: 'test'},
cache: false,
action: 'test',
success: function (data) {
jQuery('#load_data').append(data);
if (data === '') {
jQuery('#load_data_message').html("<button type='button'> No Data Found </button>");
action = 'active';
} else {
jQuery('#load_data_message').html("<button type='button'> Please Wait... </button>")
action = "inactive";
}
}
});
}
if (action === 'inactive') {
action = 'active';
load_country_data(limit, start);
}
jQuery(window).scroll(function () {
if (jQuery(window).scrollTop() + jQuery(window).height() > jQuery('#load_data').height() &&
action == 'inactive') {
action = 'active';
start = start + limit;
setTimeout(function () {
load_country_data(limit, start);
}, 1000);
}
});
});