Jump to content

php variable inside jquery


violinrocker

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.