If we need to use the php variable in our js file we can use Core Drupal.settings Functionality :
example:
Let we assume we want to use at the page load so, add this is hook_init():
function mymodule_init(){
$token_value = "this is value of your variable";
drupal_add_js(array('mymodule' => array('token' => $token_value)), array('type' => 'setting'));
}
Now get the in your js file, but make sure your js file also preloaded to website via theme.info or any other way ...
jQuery(document).ready(function(){
alert(Drupal.settings.mymodule.token);
});
That it...
- Log in to post comments