Drupal Node Id reflection
If you would like to get the current viewed nodes id you should be able to do like this:

// check so we're really viewing a node
if (arg(0) == 'node') {
  // grab the nid for the node
  $nid = arg(1);
  // you could also try to load the node to make
  // sure the supplied nid is valid
  if (node_load($nid) == FALSE) {
    // failed to load the node
  }
}


In the case of an ajax request I guess you really should supply the nid as an argument:

function &lt;MODULE&gt;_menu() {
  $items['sample/%1'] = array(
    'page callback' =&gt; '&lt;MODULE&gt;_sample',
    'page arguments' =&gt; array(1),
    'type' =&gt; MENU_CALLBACK,
    'access arguments' =&gt; array('access content'),
  };
  return $items;
}

function &lt;MODULE&gt;_sample($nid) {
  // use the supplied nid here
  $node = node_load($nid);
  if ($node) {
    // do something with the loaded node
  }
}

jQuery('#output').load('sample/21');