how to print javascript variable into php file
in my test.php file, I'm taking Titanium Data Path as javascript variable and trying to pass to php variable, but php shows error "undefined globalObject". Following is the code
<script>
var globalObject = new Object();
globalObject.foo = Titanium.API.Application.getDataPath();
</script>
<?php
$db_path = $globalObject->foo;
?>
I also tried
<script>
var globalObject = new Object();
globalObject.foo = Titanium.API.Application.getDataPath();
</script>
<script type="text/php">
$db_path = $globalObject->foo;
</script>
Php error: undefined "db_path" variable.
Any tip
2 Answers
-
The php is evaluated on the "server" before your javascript is looked at. So you can't do it the way you're trying. You'll have to pass the info to the page (querystring, form field, cookie, session variable, etc.).
-
Asif,
It won't work like that. The easiest (and fastest) method is to simply us a session variable. There's your global.