Answer the question
In order to leave comments, you need to log in
How to make an ajax request?
Hello everyone, there is some code, not when I didn’t work with ajax, I want to make the question about 70% when scrolling down, so that the content would be loaded with the offset parameters first 0, then 50,100, etc. now it's all in this form
if ($(this).hasClass('group')) {
//$('.bitrate').children('div').css('display', 'none');
VK.callMethod("resizeWindow", 800, 1275);
VK.api('audio.get', { owner_id :-1959, offset:0, count: 50}, function(pl_music2) {
if(pl_music2.response) {
$.each(pl_music2.response, function(key, value) {
key != 0 ? line += '<a id="pg'+key+'" href="'+value.url+'" class="sm2_link">'+value.artist+' - '+value.title+'</a>' : false;
});
$('.vkla.group-detail').html(line);
$('div[for="group-detail"]').trigger('click');
}
});
}
Answer the question
In order to leave comments, you need to log in
It can be something like this, it is worth modifying if that.
if ($(this).hasClass('group')) {
VK.callMethod("resizeWindow", 800, 1275);
var offset = 0,
$body = $('body'),
getData = function(offset) {
VK.api('audio.get', {
owner_id: -1959,
offset: 0,
count: 50
}, function(pl_music2) {
if (pl_music2.response) {
$.each(pl_music2.response, function(key, value) {
key != 0 ? line += '<a id="pg' + key + '" href="' + value.url + '" class="sm2_link">' + value.artist + ' - ' + value.title + '</a>' : false;
});
$('.vkla.group-detail').html(line);
$('div[for="group-detail"]').trigger('click');
}
});
};
getData(offset);
$body.on('scroll', function() {
if ((($body.scrollTop() / $body.height()) * 100) > 70) {
offset += 50;
getData(offset);
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question