There is a code that displays posts from the VKontakte group to the "answerPlaceHolder" block, so if I want to also display posts from another VKontakte group, only to another "betaFeed" block, how can this be implemented so that they don't interfere with each other?

<div id="answerPlaceHolder"></div> <div id="betaFeed"></div> <script> var placeHolder = $('#answerPlaceHolder'); var url = 'https://api.vk.com/method/wall.get?owner_id=-78812318&count=4&filter=all&v=5.45'; var answer; $.ajax ({ url: url, type: 'get', crossDomain: true, dataType: 'jsonp', success: function(response) { answer = response; answer.response.items.forEach(function(item) { var item2Append = $('<div class= "blog-post"></div>'); if((item.text != 'undefined') && (item.text != '')) { // item2Append.append('<div class="blog-header">' + item.text + '</div>'); console.log(item.text); } if( (typeof(item.attachments) !== 'undefined') && (item.attachments[0].type == 'photo') && (typeof(item.attachments[0].photo.photo_604) !== 'undefined') ) { item2Append.append('<div class="blog-header">' + item.text + '</div> <img class="blog-img" src="' + item.attachments[0].photo.photo_604 + '"><br><div class="blog-text">' + item.attachments[0].photo.text + '</div><div class="blog-share"><a href="http://gamer-by-life.com/share/?title='+ item.text + '&img='+ item.attachments[0].photo.photo_604 + '&time='+item.date + '&text=' + item.attachments[0].photo.text + '"><img src="share.png"></a></div>'); //console.log(item.attachments[0].photo.photo_604); } console.log('******************************\n'); if(item2Append.children().length != 0) { item2Append = item2Append.add('<br>'); placeHolder.append(item2Append); } }); }, error: function(error) { console.log('Ошибка'); console.log(error); } }); </script> 

    1 answer 1

    I dare to assume, for example, in this way:

     $(function() { var placeHolder = $('#answerPlaceHolder'); getVKposts(-41633702); getVKposts(-22822305); function getVKposts(groupID) { var url = 'https://api.vk.com/method/wall.get?owner_id=' + groupID + '&count=3&filter=all&v=5.45'; var answer; var d = $.ajax({ url: url, type: 'get', crossDomain: true, dataType: 'jsonp', success: function(response) { var answer; answer = response; answer.response.items.forEach(function(item) { var item2Append = $('<div class= "blog-post"></div>'); if ( (typeof(item.attachments) !== 'undefined') && (item.attachments[0].type == 'photo') && (typeof(item.attachments[0].photo.photo_604) !== 'undefined') ) { item2Append.append('<div class="blog-header">' + item.text + '</div> <img class="blog-img" src="' + item.attachments[0].photo.photo_604 + '"><br><div class="blog-text">' + item.attachments[0].photo.text + '</div><div class="blog-share"><a href="http://gamer-by-life.com/share/?title=' + item.text + '&img=' + item.attachments[0].photo.photo_604 + '&time=' + item.date + '&text=' + item.attachments[0].photo.text + '"><img src="share.png"></a></div>'); } placeHolder.append(item2Append); }); }, error: function(error) { console.log('Ошибка'); } }); } }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="answerPlaceHolder"></div> <div id="betaFeed"></div> 

    • Is there any way that for some particular group of count posts it’s acceptable not 3, but 10? - arthru 5:06
    • @arthru just call getVKjson (-41633702, 10), add function getVKjson (groupID, num) and insert num in the function - Jean-Claude
    • Can you give a sample code, please. - arthru
    • I just don’t understand where to insert it, so that the norms would work, and whether it is possible to somehow correct the order of records, otherwise when we refresh the page constantly, then the first group at the beginning is the second. - arthru