I decided to try working with VK_API without knowing JS, JSON, JQuery.

The problem is that the server gives the data in JSON, but it doesn’t work out how to process them, read a couple of guides, but not one did not work in my hands.

$('#load').on('click', loadFriends); $('#load1').on('click', loadJson); function getUrl(method, params) { params['access_token'] = ''; return 'https://api.vk.com/method/' + 'friend.search' + '?' + $.param(params) + '&v=5.72'; } function sendRequest(method, params, func) { $.ajax({ url: 'https://api.vk.com/method/friends.search?count=60&fields=photo_100&access_token=&v=5.72', method: 'GET', dataType: 'JSONP', success: function(data) { console.log(data); } }); } function loadFriends() { sendRequest('friends.search', { count: 60, fields: 'photo_100' }, function(data) { drawFriends(data.response); }); } function drawFriends(friends) { var html = ''; var f = friends[i]; html += +'<h4>' + f.first_name + '</h4>'; alert(data.response.item[1].first_name); html += +'<h4>' + cart.item[1].first_name + '</h4>'; } function loadJson() { var cart = JSON.parse(data); alert(cart.item[1].first_name); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="load">Показать друзей</button> <button id="load1">Показать друзей1</button> 

enter image description here

  • What should be done? - Alexandr Maliovaniy
  • What is the question? What did not work out specifically? - Mikhail Grebenev
  • @AlexandrMaliovaniy Let’s display a valid username or ID, I just want to understand how to display something from JSONa - Denis Gagarin
  • @MikhailGrebenev In general, nothing happened, nothing appears in HTML - Denis Gagarin
  • console.log (data [0] ['id']); - Alexandr Maliovaniy

1 answer 1

 $('#load').on('click', loadFriends); function getUrl(method, params) { params['access_token'] = ''; return 'https://api.vk.com/method/' + 'friend.search' + '?' + $.param(params) + '&v=5.72'; } function sendRequest(method, params, func) { $.ajax({ url: 'https://api.vk.com/method/friends.search?count=60&fields=photo_100&access_token=&v=5.72', method: 'GET', dataType: 'JSONP', success: function(data) { loadJson(data); } }); } function loadFriends() { sendRequest('friends.search', { count: 60, fields: 'photo_100' }, function(data) { drawFriends(data.response); }); } function drawFriends(friends) { var html = ''; var f = friends[i]; html += +'<h4>' + f.first_name + '</h4>'; alert(data.response.item[1].first_name); html += +'<h4>' + cart.item[1].first_name + '</h4>'; } function loadJson(data) { var cart = JSON.parse(data); alert(cart.item[1].first_name); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="load">Показать друзей</button> 

  • Error "Uncaught ReferenceError: data is not defined" - Denis Gagarin
  • loadJson , loadJson did not accept data - Alexandr Maliovaniy
  • Thank you so much, moved from a dead center, now a new mistake: D - Denis Gagarin
  • VM2636: 1 Uncaught SyntaxError: Unexpected token in JSON at gshg ex gsg () anxiax gfgglshpxgff (vtg.htggtgtgtgfgfggfggfggfggfggfgfgcfggfggfggfcfggfcfggggfggggfgggfgfgfggggfggfggfgcfgfgfgfgfxgxgxxxxxxxxxxxxxxxxxxxxxxxg) ) at u (jquery.min.js: 2) at Object.fireWith [as resolveWith] (jquery.min.js: 2) at k (jquery.min.js: 2) at HTMLScriptElement.n (jquery.min.js : 2) at HTMLScriptElement.dispatch (jquery.min.js: 2) at HTMLScriptElement.y.handle (jquery.min.js: 2) - Denis Gagarin
  • comment out the loadJson body and add console.log(typeof(data)); - Alexandr Maliovaniy