I am doing some processing in a back end page (thread.php) which basically returns values for a time period between dateposted and current time.
The front end page(index.php) sends a request to thread.php with the value for dateposted. The page thread.php takes in dateposted and returns the values accordingly. index.php would then use the last value of the returned values and sets dateposted as this value which is again sent in as request. So it is a loop. However, I am facing a problem sending the value “dateposted” from index.php to thread.php.
$dateposted = '1328098097623';
<script language="JavaScript">
var dateposted = <?php echo $dateposted ?>;
function returnValue()
{
$.ajax({
async: true,
type: "GET",
url: "thread.php",
data: {lastposted : dateposted},
success: function (html) {
if(html)
{
var newDiv = $('<div/>').html(html);
$('#chatContents').append(newDiv);
}
}
});
}
</script>
This is what i have in thread.php to accept the variable passed over.
if(!isset( $lastpost)){
$lastpost = 0;
}else{
$lastpost = $_REQUEST["lastposted"];
}
Basically i have hardcoded “dateposted” for now. I am not sure how to pass in php variables to the another page through ajax. Thanks in advance
With a quick look that i gave it i suggest you first rap your php echo Variable with quotes””..
this is to get your javascript syntax correct . Second replace the function(html) to function (data)..because that is the object you wanna send and change your type to POST .Last at your php script change it like this