During Drupal development, sometimes we may need to manipulate some server data in Javascript. In this case, we could create a custom module to retrieve the database data and pass it to browser such that we can it it in Javascript.
1. Implement the hook_init().
function <module-name>_init() { drupal_add_js( array( 'eureka' => array( // we should use module name for best practice 'data' => array( 'Name' => 'ykyuen', 'Blog' => 'Eureka!', 'URL' => 'https://eureka.ykyuen.info/', ), ) ), 'setting' ); }
2. Clear the cache and refresh the website, you could find the values in Drupal.settings.
Done =)