How to pass node ID argument to Drupal 7 div auto update ajax script EDIT: There seems to be a ready-to-use http://drupal.org/project/block_refresh module available as @albertski indicated, so no need to struggle to develop a new module.

I've implemented the code on https://stackoverflow.com/questions/8144436/refreshing-a-div-in-drupal to get a Drupal 7 node page division auto-updated. Here is the code outputting simple time() function:

Hook menu:

$items['autoupdate'] = array(
'title' =&gt; 'Resize',
'page callback' =&gt; 'block_update',
'access callback' =&gt; TRUE,
'type' =&gt; MENU_LOCAL_TASK,
  );


Function itself:

function block_update(){
$html = time();
print drupal_json_encode(array('html' =&gt; $html)); exit(); }


Javascript: 

    function autoupdate() {
  //alert('autoupdate is running');
  jQuery.ajax(
  {
    type: "POST",
    url: "/autoupdate",
    cache: false,
    success: function(data) {
      var result = JSON.parse(data);
      jQuery("div.autorefresh").fadeIn("slow").html(result['html']);
    }
  });
  //alert('autoupdate is complete');
}
setInterval("autoupdate()", 2500);


However, instead of time() I would like to use node variables and having troubles to make the module to see $node. Even if I put my div on a node page and call menu_get_object() the javascript sees only the content /autoupdate page:

function block_update(){
  $html = arg(0);
  print drupal_json_encode(array('html' =&gt; $html));
  exit();
}


shows: autoupdate

I tried to change the path in both hook menu and javascript from autouptade to node/%node/update, but unfortunately javascript doesn't want to recognize %node as argument. I am afraid it recognizes only static URLs. But then how is it possible to pass node ID to javascript?
I probably would have done this differently but than again I'm not a hundred percent sure what you are doing.

In response how can you pass the node id to javascript. Perhaps in hook_page_alter():

$node = menu_get_object();
if ($node) {
  drupal_add_js(array('your_module_name' =&gt; array('nid' =&gt; $node-&gt;nid), 'setting');
}


Then in your ajax code get the nid via:

Drupal.settings.your_module_name.nid