There are two js codes:

- one prints up to 1000 elements (containing aid and owner_id):

function recommendate(){ VK.Api.call('audio.getRecommendations', {count: '1000'}, function(r) { if(r.response) { $('#playlist').empty().append($.map(r.response, function(song){ return '<li><a href="'+ song.url +'"><b>'+song.artist+'</b> - '+ song.title +'</a><div class="add-song" data-aid="'+ song.aid +'" data-aid-id="'+ song.owner_id +'"></div><a href="javascript:addaudio();">+</a></li>' })) } }); }; 

- the second you need to pass the parameters and execute the code

 function addaudio() { VK.Api.call('audio.add', { audio_id: Сюда song.aid , owner_id: Сюда song.owner_id }, function (data) { if (data.response) { console.log(data.response); } }); }; 

Question: how can I, when I click on +, transfer all this to js and execute the query? Actually you need to take the song.aid and song.owner_id.

    1 answer 1

    You can add additional attributes in <a href="javascript:addaudio();">+</a>

     function recommendate(){ VK.Api.call('audio.getRecommendations', {count: '1000'}, function(r) { if(r.response) { $('#playlist').empty().append($.map(r.response, function(song){ return '<li><a href="'+ song.url +'"><b>'+song.artist+ '</b> - '+ song.title +'</a><div class="add-song" data-aid="'+ song.aid +'" data-aid-id="'+ song.owner_id + '"></div><a data-audio-id="'+song.aid+'" data-owndr_id="'+ song.owner_id+'" href="javascript:addaudio();">+</a></li>' })) } }); 

    And access these attributes on click.

    Update

    I'd rather remove href="javascript:addaudio();" because I don’t even know how to transfer the call context in this case :) It’s better to use the usual addition of a listener per click, for example, my decision . PS Adding a listener needs to be implemented after the execution of the recommendate function, otherwise the script simply will not find pluses.

    • and in the second code how to transfer these attributes? - Olejokkk Nov.
    • <a data-audio-id="264255333" data-owndr_id="22260495"> + </a> so right now in the browser looks like a line, respectively, when you click on + nothing happens I am not very good in js, help me pliz You can explain this in more detail)) - Olejokkk