rx3mer Posted February 16, 2014 Share Posted February 16, 2014 Hi guys, I am trying to figure out how to pass PHP ID (page.php?id= 'id' ") with ajax request. Getting the ID and storing it into variable called "playlistsongid" <?php session_start(); if(!isset($_GET['id'])) die("No id set"); ?> <?php $playlistsongid = $_GET['id']; ?> function setupyoutubesongarray(firstload) { $.ajax({ 'url': 'post.php', 'async': false, success: function (response) { var posturl="post.php"; // needs to looks something like post.php?id= $.getJSON(posturl,function(data){ youtubesongs = []; $.each(data.members, function(i,song){ result = (song.SongUrl); youtubesongs.push(result); //ytplayer_playlist.push(result); }); loadnextbatchfromsongsarray(); if (firstload = 1) { ytplayer_render_player(); } }); } }); } Any help would be much apreceated! Quote Link to comment https://forums.phpfreaks.com/topic/286227-pass-php-id-with-ajax-request/ Share on other sites More sharing options...
Solution Ch0cu3r Posted February 16, 2014 Solution Share Posted February 16, 2014 (edited) You'd pass the id in the url: like you do with a hyperlink 'url': 'post.php?id=id-here', If your id is in javacript variable then use 'url': 'post.php?id=' + your_js_id_variable, Edited February 16, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286227-pass-php-id-with-ajax-request/#findComment-1469124 Share on other sites More sharing options...
rx3mer Posted February 16, 2014 Author Share Posted February 16, 2014 Thank you! Just had to convert the php to js veriable and the job was done. <?php $var = "a value"; ?> <script> jsvar = '<?php echo $var ;?>'; alert(jsvar); </script> Quote Link to comment https://forums.phpfreaks.com/topic/286227-pass-php-id-with-ajax-request/#findComment-1469145 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.