violinrocker Posted May 9, 2011 Share Posted May 9, 2011 i used the code below and i want to put $session->username into url: "addons/functions/ajax_more.php", so that it would be like url: "addons/functions/ajax_more.php?name=$session->username", because the code i have in ajax_more.php requires $session->username... the only options i could think of is $_Post and $_get but i really dont know jquery. $(function() { //More Button $('.more').live("click",function() { var ID = $(this).attr("id"); if(ID) { $("#more"+ID).html('<img src="moreajax.gif" />'); $.ajax({ type: "POST", url: "addons/functions/ajax_more.php", data: "lastmsg="+ ID, data: "username="+ ID, cache: false, success: function(html){ $("ol#updates").append(html); $("#more"+ID).remove(); } }); } else { $(".morebox").html('The End'); } return false; }); }); this is whats inside ajax_more.php... at first i included a php file from which $session->username is from, but then it posts an error like session_start() [function.session-start]: Cannot send session cache limiter - headers already sent if(isSet($_POST['lastmsg'])) { $lastmsg=$_POST['lastmsg']; $str = "SELECT * FROM news_feed INNER JOIN friends ON news_feed.name = friends.friendname WHERE friends.username = '$session->username' and id<'$lastmsg' ORDER BY date DESC LIMIT 10 "; Link to comment https://forums.phpfreaks.com/topic/235933-php-variable-inside-jquery/ Share on other sites More sharing options...
.josh Posted May 9, 2011 Share Posted May 9, 2011 url: "addons/functions/ajax_more.php?name=<?php echo $session->username; ?>", then use $_POST['name'] in ajax_more.php Link to comment https://forums.phpfreaks.com/topic/235933-php-variable-inside-jquery/#findComment-1212860 Share on other sites More sharing options...
.josh Posted May 9, 2011 Share Posted May 9, 2011 alternatively, you should be able to use $session->username if you have session running..and that is a valid object/property.. where are you trying to put session_start()? It should be at the very beginning of your ajax_more.php file, before any other output. Link to comment https://forums.phpfreaks.com/topic/235933-php-variable-inside-jquery/#findComment-1212863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.