this may be related to passing php variables to javascript,
but say i have an ajax function ( call this file1.php)
that calls a php file ( call this file2.php) that itself has ajax in it.
which, say calls for a file3.php
in file1.php, i collect information that i put into a querystring, passed to file2.php.
file2.php can use the querystring info via $_GET
but how do i tell file2.php to incorporate the variable into the querystring of its ajax calls to file3.php?
currently i have this- it looks right for the most part but won't work
file1.php
<html>
<body>
<script language="javascript" type="text/javascript">
function gotofile2(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = document.getElementById('key').value;
var queryString = "?key=" + key;
ajaxRequest.open("GET", "file2.php" + queryString, true);
ajaxRequest.send(null);
}
</script>
<form name='myForm'>
key: <input type='text' id='key' /> <br />
<input type='button' onclick='gotofile2()' value='something' />
</form>
<div id='ajaxDiv'>result</div>
</body>
</html>
file2.php
<html>
<body>
<?
$key = $_GET['key'];
echo $key;
?>
<script language="javascript" type="text/javascript">
function gotofile3(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = <? echo $key?>;
// this var key bit is the bit i can't get
var queryString = "?key=" + key;
ajaxRequest.open("GET", "file3.php" + queryString, true);
ajaxRequest.send(null);
}
</script>
<form name='myForm'>
<input type='button' onclick='gotofile3()' value='something' />
</form>
<div id='ajaxDiv'>result</div>
</body>
</html>