PHP for loop not working with jQuery API (Uncaught TypeError) -
so have array full of youtube video id's i'm trying load jquery. reason it's not working, it's giving me error in console:
code:
<script type='text/javascript'> $(document).ready(function() { <?php $videos = array("vgh5dv0d3wk", "6y_njg-xoee", "9q31j3mkcky"); ($i = 0; $i < count($videos); $i++) { ?> // ----------- $.get( "https://www.googleapis.com/youtube/v3/videos", { part: 'snippet', key: 'aizasydywpzlevxaui-ktsvxtlrolyheonuf9rw', id: '<?php echo $videos[$i]; ?>', }, function(data) { $('#playlist-item-<?php echo $i; ?>').text(data.items[<?php echo $i; ?>].snippet.title); }); <?php } ?> }); </script>
the response having 1 item. don't have increment array index.
use below code.
$('#playlist-item-<?php echo $i; ?>').text(data.items[0].snippet.title);
Comments
Post a Comment