简体   繁体   中英

Drupal multiple ajax calls to a custom module

I have the following code in my custommodule_menu right now there is one ajax call to it. I want to add another and consequently create a new function (a new page callback) to handle it, how would i do this.

function a_b_menu() {
   $items['/a_b/email/%'] = array(
      'page callback' => 'a_b_ajax_email',
      'type' => MENU_CALLBACK,
      'page arguments' => array(1),
      'access arguments' => array('access content'),
      'access callback' => TRUE,

   );
   return $items;
}

You just need to do the following:

$items['/a_b/email/%'] = array(
    'page callback' => 'a_b_ajax_email',
    'type' => MENU_CALLBACK,
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'access callback' => TRUE,

);

$items['/a_b/new_page/%'] = array(
    'page callback' => 'a_b_ajax_new_page',
    'type' => MENU_CALLBACK,
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'access callback' => TRUE,

);

Then since no file key is defined in the menus $items array for where the methods are stored, find a_b_ajax_email method in the same file and copy/paste this and rename to a_b_ajax_new_page. Then go ahead and change the functionality to suit your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM