Whats the best method of capturing a javascript variable sent using POST to a php file ?
My line of code that posts the variable is given below
xmlHttp.open("GET", "testAJAX.php?$phpvariable="+$jsvariable, true);
Cheers
Whats the best method of capturing a javascript variable sent using POST to a php file ?
My line of code that posts the variable is given below
xmlHttp.open("GET", "testAJAX.php?$phpvariable="+$jsvariable, true);
Cheers
I'll bet the problem is you've confused yourself with the $
sign.
Change:
xmlHttp.open("GET", "testAJAX.php?$phpvariable="+$jsvariable, true);
To:
xmlHttp.open("GET", "testAJAX.php?phpvariable="+jsvariable, true);
Why?
Because calling $_GET['$phpvariable']
(single quotes) would give you the value of the parameter, whereas calling $_GET["$phpvariable"]
(double quotes) would give you nothing! The $phpvariable
inside double quotes would be assumed to be a PHP variable rather than a parameter name, and it would attempt to use the contents of the PHP variable (which probably doesn't exist) as the parameter name. (A parameter sent over HTTP is not a PHP variable.)
But if you don't include that $
in your request parameter name, then both single and double quotes will work: $_GET['phpvariable']
or $_GET["phpvariable"]
.
Also, Javascript variables don't begin with $
(not normally, although they can): I almost didn't catch that mistake.