I have menu on left column, When we click menu-link I need to post data in right column without page refresh. I am looking to ajaxify menu.
Could you please give me an example how to ajaxify menu links?
This is really simple by using Drupal ajax framework.
First, define your menu callback page.
/**
* Implements hook_menu().
*/
function yourmodule_menu() {
$items = array();
$items['yourmodule/callback-page'] = array(
'title' => 'AJAX callback - refresh the elements on the right hand',
'page callback' => 'yourmodule_refresh',
'page arguments' => array(1),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
Secondly, do ajax deliver on callback page.
/**
* Menu callback.
*/
function yourmodule_refresh($action, $type) {
if ($type != 'ajax') {
// This is js only.
return 'Oh well';
}
$content = t('What ever you want');
$commands = array();
$commands[] = ajax_command_replace('.right-hand-wrapper-class', $content);
$page = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($page);
}