wesley tanaka

Pass PHP variables to Javascript in Drupal 6

‹ How to tell it's spring, method #734 | Olfactory SMS ›
()

To access PHP values and variables from Javascript using Drupal, you can send them to your javascript code using Drupal's drupal_add_js as follows:

drupal_add_js(array('mymodule' => array(
'username' => 'Mike',
'uid' => 123,
'likes' => array('ice cream', 'peanuts', 'coffee'),
)), 'setting');

Then in Javascript, you can use your variables which will appear inside Drupal.settings:

alert(Drupal.settings.mymodule.username);

Javascript to PHP

I've started implementing this technique, but I'd like to know how to pass variables from Javascript to the variables table without refreshing the page. Any ideas?

You can do this using

You can do this using AJAX

 

Cheers

Syndicate content