2

I have the following file structure:

enter image description here

Now I want to use the variables from the dropdown menu's (that are in the get_attributes.php, get_fields.php and in the get_tables.php) in my main.js and in getData.php . Now the question is how can use a variable from another .php file in a .js file?

L. Grunn
  • 175
  • 2
  • 15
  • here is the answer of your question [Access PHP var from external javascript file](http://stackoverflow.com/questions/2928827/access-php-var-from-external-javascript-file) – sorrow poetry May 17 '16 at 07:43
  • 1
    Possible duplicate of [How to pass variables and data from PHP to JavaScript?](http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript) – Satej S May 17 '16 at 07:44

1 Answers1

2

You can't directly use PHP variables from JS scripts.

Dynamic access

If you want get variables dynamically you can use AJAX (see jQuery AJAX doc ).

Static access

If you want to access PHP variables when your JS app start you can put PHP variables in the DOM by using this syntax :

<input type="hidden" id="php_name" value="<?=$name?>" />

And use jQuery to get it :

$('#php_name').val();

I hope it will help.

Samuel Dauzon
  • 10,744
  • 13
  • 61
  • 94