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:

enter image description here

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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -