I have tried in my custom module:
Declaring a path for Ajax callback
function custom_menu() {
$items['ajax-block/%'] = array(
'title' => 'Ajax test callback',
'type' => MENU_CALLBACK,
'page callback' => 'ajax_link_callback',
'page arguments' => array(1),
'delivery callback' => 'ajax_deliver',
'access arguments' => array('access content'),
);
return $items;
}
now the callback itself
/**
* Callback ajax
*/
function ajax_link_callback($from_cid, $mode = NULL) {
if ($mode != 'ajax') {
drupal_set_message('Turn Javascript');
drupal_goto(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '<front>');
}
$commands[] = ajax_command_html('.region-content', some_func());
return array('#type' => 'ajax', '#commands' => $commands);
}
I have a few manually created links:
<a class="use-ajax" href="/ajax-block/1/nojs">link1</a>
<a class="use-ajax" href="/ajax-block/2/nojs">link2</a>
<a class="use-ajax" href="/ajax-block/3/nojs">link3</a>
Now I need such functionality - when I press link1 - block1 loads content in to .region-content, when I click link2 - block2 and etc.
How can I do this?