Hi,

I have a javascript file which uses JQuery to do AJAX. Well, I want to know if it is possible to pass "user id" to the PHP file to return different results depending on user's role.

Thanks

Comments

nicksanta’s picture

you could use Drupal.settings to expose the current user id to js scripts.

In your module

<?php
/**
 * Implement hook_init
 */
function yourmodule_init() {
  global $user;
  drupal_add_js(array('currentUser' => $user->uid), 'setting');
}
?>

And then in your js, access the uid like this:

uid = Drupal.settings.currentUser;

----------------------
Nick Santamaria

ashwani867’s picture

Hi, I was wondering as this has to be written in the init hook so will it require disabling and enabling the module for this code to work.