J
J
jackie chan2015-11-11 20:35:09
JavaScript
jackie chan, 2015-11-11 20:35:09

Undefined in all parameters why?

Again, because of my carelessness, I make mistakes somewhere, there is a code

<script type="text/javascript">
    VK.init({
        apiId: 5135424
    });
  function recommendate(){
    VK.Api.call('audio.getRecommendations', {}, function(r) {
      if(r.response) {
        $('#playlist').append('<li><a href="'+r.response.url+'"><b><'+r.response.artist+'></b> - '+r.response.title+'<span class="label"><'+r.response.aid+'></span></a></li>')       
      }
    });
  };
</script>

The response from VK has the following structure: VK.Api._callbacks[8402834]({"response":[{"aid":325739565,"owner_id":23303547,"artist":"Caspian Cargo, Guf","title":" All for $1 [New Rap] ","duration":298,"url":"http:\/\/cs9-4v4.vk.me\/p14\/........"," lyrics_id":"91370596","genre":18}
In all parameters that are displayed Undefined
And how to make it a cycle, otherwise only 1 record is displayed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Wolf, 2015-11-11
@onvorobyov

well, in the response array, so use itr.response[0].url

A
Alexey Ukolov, 2015-11-11
@alexey-m-ukolov

"response":[{}]
r.response contains an array of objects, and you are trying to work with it as if it were an object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question