rx3mer Posted February 12, 2014 Share Posted February 12, 2014 Hi guys, I am trying to build a simple web app that takes data from database, converts it into jason and inserts the data into a veriable that should act as a playlist. I want to make the veriable called "songs" to be equals the result and insert it into ytplayer_playlist. Any guides will be very helpfull! var songs; function addsongs(event) { $.ajax({ url: 'post.php', success: function (response) { var url="http://localhost/xampp/websites/youtubeAPI/post.php"; $.getJSON(url,function(data){ $.each(data.members, function(i,song){ result = (song.SongUrl); console.log(result); }); }); } }); } ytplayer_playlist.push('tGvHNNOLnCk'); Quote Link to comment https://forums.phpfreaks.com/topic/286148-global-veriable-outside-json/ Share on other sites More sharing options...
Solution requinix Posted February 12, 2014 Solution Share Posted February 12, 2014 (edited) the veriable called "songs" to be equals the resultLooks like it should be an array and then you can .push the URLs or whatever into it. var songs = []; songs.push(result); and insert it into ytplayer_playlist.What does "insert" mean? The .push you have down below? Copy that. ytplayer_playlist.push(result);And now the songs variable looks extra because you're inserting directly into the ytplayer thing? Or do you need it yourself somewhere? Edited February 12, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/286148-global-veriable-outside-json/#findComment-1468666 Share on other sites More sharing options...
rx3mer Posted February 12, 2014 Author Share Posted February 12, 2014 I think the problem comes from the song not being loaded instantly on the page. If i do this "ytplayer_playlist.push('tGvHNNOLnCk');" it works, but when i add the veriable "ytplayer_playlist.push(result);" it doesen't work... Quote Link to comment https://forums.phpfreaks.com/topic/286148-global-veriable-outside-json/#findComment-1468668 Share on other sites More sharing options...
requinix Posted February 13, 2014 Share Posted February 13, 2014 What's the value of result? Maybe it's a complete URL and not just the identifier? Quote Link to comment https://forums.phpfreaks.com/topic/286148-global-veriable-outside-json/#findComment-1468673 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.