How to use user_load() for user on $_GET[] request in Drupal way? I'm trying to get UID of users on $_GET[] request, following is my module code:

my_module.module

function hover_card_init() {
  $module_path = drupal_get_path('module', 'hover_card');
  drupal_add_js($module_path . '/javascripts/hover_card.js');
  drupal_add_js(array('hover_card' =&gt; array('module_path' =&gt; $module_path)), array('type' =&gt; 'setting', 'scope' =&gt; JS_DEFAULT));
}

function hover_card_menu() {
  $items['hover-card'] = array(
    'title' =&gt; 'Hover Card',
    'page callback' =&gt; 'hover_card',
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}

function hover_card() {
  $id = $_GET['id']; // Get UID using JS, not a Drupal way!
  $user_fields = user_load($id);

  if (isset($user_fields-&gt;name) &amp;&amp; !empty($user_fields-&gt;name)) {
    $name = $user_fields-&gt;name;
  }

  $array = array(
    'name' =&gt; $name,
  );

  return theme('hover_card_template', array('details' =&gt; $array));
}


my_module.js

(function ($) {
  Drupal.behaviors.hover_card = {
    attach: function (context, settings) {
      var module_path = Drupal.settings.hover_card.module_path;
      var hoverUserDetails = '&lt;div class="hover-details"&gt;&lt;/div&gt;';
      $("a.username").hovercard({
        detailsHTML: hoverUserDetails,
        width: 250,
        onHoverIn: function () {
          var user_id = $(this).find("a").attr("href").split("/");
          var hover_details = $(".hover-details");
          $.ajax({
            url: Drupal.settings.basePath + "hover-card",
            type: 'GET',
            data: {
              id: user_id[3] // What should I do here? As this is not a clean and Drupal way :-(
            },
            beforeSend: function () {
              hover_details.empty();
              hover_details.prepend('Loading...');
            },
            success: function (data) {
              hover_details.html(data);
            },
            complete: function () {
              $('.loading-text').remove();
            }
          });
        }
      });
    }
  };
})(jQuery);
As said in the comment for the question, you should use placeholders in your menu definition.

function hover_card_menu() {
  $items['hover-card/%user'] = array(
    'title' =&gt; 'Hover Card',
    'page callback' =&gt; 'hover_card',
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );

  return $items;
}


Then you can pass the user ID for the currently logged-in user to the JavaScript code, instead of passed the module path, which is irrelevant.

function hover_card_init() {
  $module_path = drupal_get_path('module', 'hover_card');
  drupal_add_js($module_path . '/javascripts/hover_card.js');
  drupal_add_js(array('hover_card' =&gt; array('user_id' =&gt; $GLOBALS['user']-&gt;uid)), array('type' =&gt; 'setting', 'scope' =&gt; JS_DEFAULT));
}


The JavaScript code doesn't need to know the module path, since it will make an AJAX call to hover-card/%user which is not related to the module path in any way.