...

View Full Version : Setting a PHP variable with AJAX



crazyracky
04-12-2011, 02:44 AM
Hey,

I want to use AJAX to set a PHP variable from a JavaScript variable.
My code is




xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("display_routes").innerHTML=xmlhttp.responseText;

}
}

xmlhttp.open("GET","getRoute.php?q="+whereClauseString+"&page="+resultsPage+"&limit="+resultsLimit+"&sort="+sortBy+"&zoom="+currentZoom+"&center="+currentCenter,true);
xmlhttp.send();



In the Ajax file getRoute.php I have




<?php
$q = $_GET["q"];
$page = $_GET["page"];
$limit = $_GET["limit"];
$sort = $_GET["sort"];
session_start();
$_SESSION['zoom'] = $_GET["zoom"];
$_SESSION['center'] = $_GET["center"];

require_once ('includes/mysql_connect.php');

$r = mysql_query("SELECT * FROM routes WHERE ".$q." ORDER BY ".$sort." LIMIT ".$limit);



.....etc

All the code from then on works and it displays the response text perfectly, but the sessions aren't registering for zoom and center.

Any help guys?
Thanks

sunfighter
04-19-2011, 10:38 PM
Why do you send variables that are going to be put into sessions to the server to be installed? Why don't you just do it before making the ajax call?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum