0

I am using hook_menu to setup a link which I'm calling via JQUERY from an AJAX application. My hook implementation is as follows:

function staff_filter_menu(){
$items = array();
$items['staff/filtering/results/%'] = array(
    'page callback' => 'staff_filter_function',
    'page arguments' => array(3),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'delivery callback' => 'staff_filter_deliver',
);
return $items;

}

This link is the point of contact for my ajax app which is a simple textfield where users type in some input. *staff_filter_function* searches the database and returns some matching data. Ajax code is as follows:

$.ajax({
url: Drupal.settings.CALL_BACK + '/' + $(this).val(),
success: function($data){
       .... more stuff done here
    }
});

It all works perfectly well but for one small detail. I want to allow a shortcut which will allow all results to display. This shortcut is simply typing a single space. But, because hook_menu is expecting an argument at the end of the url, my ajax request fails whenever I type in a space. It works perfectly when I type in real content.

This is just for completeness and it a nice to have feature ... if anyone can share some ideas, I'll be very great greatful.

apaderno
  • 28,547
  • 16
  • 75
  • 90
sisko
  • 9,604
  • 20
  • 67
  • 139

1 Answers1

1

Maybe you don't need to add an argument at the end of the URL. Just make change you code to the following:

function staff_filter_menu(){
$items = array();
$items['staff/filtering/results'] = array(
    'page callback' => 'staff_filter_function',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'delivery callback' => 'staff_filter_deliver',
);
return $items;

and make a slight change to your page callback function

function staff_filter_function($my_arg = "")
{
// your code goes here
}

and you can treat $my_arg as your page argument.

Hope it works, Muhammad

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105