Skip to content

Instantly share code, notes, and snippets.

@martsie
Created January 25, 2017 11:04
Show Gist options
  • Save martsie/daae1e971809656fe6b136753d112e65 to your computer and use it in GitHub Desktop.
Save martsie/daae1e971809656fe6b136753d112e65 to your computer and use it in GitHub Desktop.
hook_menu implementation for AJAX commands
<?php
/**
* Implements hook_menu().
*/
function MY_CUSTOM_MODULE_menu() {
// Returns AJAX commands if the user has JavaScript turned on.
$items['my-custom-path/ajax'] = array(
'title' => 'My custom ajax callback',
'page callback' => 'MY_CUSTOM_MODULE_ajax_callback',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// Returns a Non-JavaScript alternative.
$items['my-custom-path/nojs'] = array(
'title' => 'My custom non-javascript callback',
'page callback' => 'MY_CUSTOM_MODULE_nojs_callback',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// The page that will run the command.
$items['my-custom-path/trigger-page'] = array(
'title' => 'AJAX trigger page',
'page callback' => 'MY_CUSTOM_MODULE_trigger_page',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment