Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked July 13th 2010 by Asif Kilwani
  • javascript
  • php
0 Comments

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.).

    — answered July 13th 2010 by Tim Poulsen
    permalink
    0 Comments
  • Asif,
    It won't work like that. The easiest (and fastest) method is to simply us a session variable. There's your global.

    — answered July 13th 2010 by null null
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.