I get an object from youtube and upload data to a table on the site. There is a code:

productsModule.controller("addNewVideo", function ($scope, $http, $rootScope) { $scope.addNewVideo = function () { /*====== GET DATA FROM YOUTUBE API =========*/ $.getJSON('https://www.googleapis.com/youtube/v3/videos?id=' + $scope.videourl + "&key=AIzaSyDnyf5NK_oWcdWjFw6VrILvGg2STG292eE&part=snippet&callback=?", function (data) { if (typeof (data.items[0]) != "undefined") { var title = ""; title = JSON.stringify(data.items[0].snippet.title); title = title.substring(1, title.length - 1); title = title.split("-"); console.log(data.items[0]); //====== CREATE OBJECT OF NEW SONG var newSong = { "artist": title[0], "song": title[1], "songID": $scope.videourl } // $scope.videourl = "test11" ; var tr = '<tr><td class=" songID hide" contenteditable="false">' + $scope.videourl + '</td><td id="artistName" class="x2" name="x1" contenteditable="true">' + title[0] + '</td> <td id="songName" contenteditable="true">' + title[1] + '</td><td> <span class="table-remove glyphicon glyphicon-remove"></span></td><td> <span class="table-play glyphicon glyphicon-play-circle"></span></td><td> <span class="table-save glyphicon glyphicon-save"></span></td></tr>'; $("#songTable").append(tr); 

I get a string on my website with data. (There may be as many lines as possible) the next act of Marlezonsky ballet - when I click on the "save" button, I have to pick up the data from my HTML page and send it to the database. You need to pick up the ID, the name of the artist and the name of the song. I can't get through to the data.

 // add song to table songs $('.table-save').click(function () { // удалить запись о песне // var x1 = $(this).find("x1").value; var x1 = $(this).parent().find(".x2").val; alert(x1); 

came to the fact that I get a lot of data ... but what next ???

enter image description here

  • Try var x1 = $(this).parent().parent().find(".x2").val; - L. Vadim
  • @ L.Vadim does not work, it gives a lot of data, but in fact nothing is needed. - Michael
  • You can put the full code in question with html - L. Vadim
  • Your много данных is a function that should have been called. - vp_arth

1 answer 1

Thank you all - figured it out. If anyone needs it, here is the valid code:

  $('.table-save').click(function () { var newSongObj = {}; $(this).parent().parent().find(".x2").each(function () { var objAttr = $(this).attr("id"); newSongObj[objAttr] = $(this).html(); }) console.log(newSongObj); $http.post('/addSongToDB', newSongObj).then(function (response) { //alert(JSON.stringify(response.data)); var xxx = JSON.stringify(response.data); });