Currently, I have a Javascript file (running on the client) that I call a PHP file(on the server) from. After the PHP file finishes, I would like to pass three variables back to the javascript that is running on the client. I figured out how to make the javascript wait for the php file for finish executing, so that is not the problem. The problem is passing the variables back to the javascript file. Can this be done? All the examples that I have seen have has some sort of hybrid javascript/php file. I was hoping to find some way to pass the php variables kind of like the jquery.ajax does. I don't know if this can be done because I am so new to Javascript and PHP. Thanks,
javascript:
<html>
<head>
<title>Login Page</title>
</head>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script language="Javascript">
function calculations(callback)
{
var x = <?php echo $username?>;
alert(x);
var password = window.prompt("Please Type Your Password");
}//ends the calculations function
function getUsername()
{
var username = window.prompt('Please Type Your Username');
var temp = document.getElementById('temp');
temp.innerHTML = username;
jQuery.ajax(
{
type: "POST",
url:"GetInfo.php",
data: "username="+username,
success: function(msg)
{callback.call();}
});//ends the jQuery send
}//ends the GetUsername function
</script>
<body onLoad=getUsername()>
<div id="temp">This will show text</div>
<body>
</html>
php:
<?
//$username = $_POST['username'];
$username = "tom";
$inFile="MyID.config.php";
$handle=fopen($inFile, 'r') or die ("No credentials could be gotten because the file MyID.config.php would not open.");
$data='0';
do{
$data = fgets($handle);
$temp = substr($data,0, 10);
//echo $temp.strcmp($temp,'\'username\'')."\n";
}while (strcmp($temp, '\'username\'')!= 0);
$data = substr($data,15,strlen($username));
if (strcmp($data, $username == 0) )
{
$read_in = fgets($handle);
$x = substr($read_in,8,-3);
$read_in = fgets($handle);
$y = substr($read_in,8,-3);
$read_in = fgets($handle);
$salt = substr($read_in,11,-3);
}//ends the strcmp $data and $username if statement.
fclose($handle);
?>