Guest User

Untitled

a guest
Apr 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <div id="answerPlaceHolder"></div>
  2. <script>
  3. var placeHolder = $('#answerPlaceHolder');
  4. var url = 'https://api.vk.com/method/wall.get?owner_id=-78812318&count=20&filter=all&v=5.45';
  5. var answer;
  6. $.ajax ({
  7. url:url,
  8. type:'get',
  9. crossDomain:true,
  10. dataType:'jsonp',
  11. success:function(response) {
  12. answer = response;
  13. var counter = 1;
  14. answer.response.items.forEach(function(item) {
  15. // console.log('Пост № ' + counter);
  16. if ((item.text != 'undefined') && (item.text != '')) {
  17. placeHolder.append('<div class="blog-header">' + item.text + '</div>');
  18. //console.log(item.text);
  19. }
  20. // console.log(item);
  21. if ((typeof(item.attachments) != = 'undefined') &&
  22. (item.attachments[0].type == 'photo') &&
  23. (typeof(item.attachments[0].photo.photo_604) != = 'undefined')) {
  24. placeHolder.append(
  25. '<img width="560px;" src="' + item.attachments[0].photo.photo_604 + '"> <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 + '"><img src="share.png"></a></div>'
  26. );
  27. // console.log(item.attachments[0].photo.photo_604);
  28. }
  29. counter++;
  30. console.log('******************************n');
  31. placeHolder.append('<br>');
  32. });
  33. },
  34. error:
  35. function(error)
  36. {
  37. console.log('Ошибка');
  38. console.log(error);
  39. }
  40. });
  41. </script>
  42.  
  43. <div class="blog-header">Тут текст (когда он есть) </div><img width="560px;" src="картинка"><br>
  44.  
  45. <div class="post"><div class="blog-header">Тут текст (когда он есть) </div><img width="560px;" src="картинка"><br></div>
  46.  
  47. //...
  48. answer.response.items.forEach(function(item) {
  49. // console.log('Пост № ' + counter);
  50. var post = $("<div class='post'>");
  51. placeHolder.append(post);
  52. if ((item.text != 'undefined') && (item.text != '')) {
  53. post.append('<div class="blog-header">' + item.text + '</div>');
  54. //console.log(item.text);
  55. }
  56. // console.log(item);
  57. if ((typeof(item.attachments) !== 'undefined') &&
  58. (item.attachments[0].type == 'photo') &&
  59. (typeof(item.attachments[0].photo.photo_604) !== 'undefined')) {
  60. post.append('<img width="560px;" src="' + item.attachments[0].photo.photo_604 + '"> <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 + '"><img src="share.png"></a></div>');
  61. // console.log(item.attachments[0].photo.photo_604);
  62. }
  63. counter++;
  64. console.log('******************************n');
  65. post.append('<br>');
  66. });
  67. //...
  68.  
  69. placeHolder.append('<div class="post"><div class="blog-header">' + item.text + '</div></div>');
Add Comment
Please, Sign In to add comment