I have created my custom module.I need to passed the fetched database value $flag=1 to js file in drupal 7.In js file I caught 'undefined variable aniv' in js file
module file
$flag=1; //assume fetched from database
drupal_add_js(array('one_time_popup' => array('aniv' => $flag)), array('type' => 'setting'));
drupal_add_js(drupal_get_path('module', 'one_time_popup') . '/service.js','file');
$settings=variable_get('one_time_popup_effects',(ONE_TIME_POPUP_DEFAULT));
drupal_add_js(array('onetimepopupmenu'=>$settings),'settings');
service.js
console.log(Drupal.settings.one_time_popup.aniv);
I think one possible problem is the line
drupal_add_js(array('onetimepopupmenu'=>$settings),'settings');
It should be setting
not settings
drupal_add_js(array('onetimepopupmenu'=>$settings),'setting');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.