I defined the following menu item on my module:
function visita_virtual_menu(){
$items = array();
$items['visita_virtual/marker_selected_handler'] = array(
'title' => t('Marker Selected Handler'),
'description' => t('Ajax handler for selected markers'),
'type' => MENU_CALLBACK,
'access arguments' => array('access panoramas'),
'callback' => 'marker_selected_handler');
return $items;
}
And even created an special permission for my module:
function visita_virtual_permission(){
return array('access panoramas' => array(
'title' => t('Configurar Panoramas'),
'description' => t('Configurar la visita virtual'),
)
);
}
Obviously the access panoramas permission appeared on the People Permissions configuration tab on Drupal. I assigned it for anonymous users, logged users, and administrator users (Just for testing purposes).
Now my javascript function does the following:
alert('Callback URL: '+url);
$.ajax({
type : "POST",
url : url,
data : {
'marker_latitude' : location.lat,
'marker_longitude' : location.lng,
},
success : function(data){
alert('Entro a la funcion success');
},
error: function(xmlhttp) {
alert('An error ocurred: '+xmlhttp.status);
}
});
The alert('Callback URL: '+url);
line shows the following info:
/drupal/visita_virtual/marker_selected_handler
However I'm always getting 403 access forbidden error. Why?? What I'm doing wrong???
I have been debugging the server's code, and the problem seems to be at this piece of code on menu.inc.
function menu_execute_active_handler($path = NULL, $deliver = TRUE) {
// Check if site is offline.
$page_callback_result = _menu_site_is_offline() ? MENU_SITE_OFFLINE : MENU_SITE_ONLINE;
// Allow other modules to change the site status but not the path because that
// would not change the global variable. hook_url_inbound_alter() can be used
// to change the path. Code later will not use the $read_only_path variable.
$read_only_path = !empty($path) ? $path : $_GET['q'];
drupal_alter('menu_site_status', $page_callback_result, $read_only_path);
// Only continue if the site status is not set.
if ($page_callback_result == MENU_SITE_ONLINE) {
if ($router_item = menu_get_item($path)) {
if ($router_item['access']) {
if ($router_item['include_file']) {
require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
}
$page_callback_result = call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
}
else {
$page_callback_result = MENU_ACCESS_DENIED;
}
The $path
parameter is getting it's default value. NULL, and then the $read_only_path
is obtained from the q
$_GET
value, for this case the $read_only_path has it's value set on: visita_virtual/marker_selected_handler
Is that ok?? shouldn't it be /drupal/visita_virtual/marker_selected_handler
?
At this point $router_item = menu_get_item($path)
I'm getting a $router_item that has an 'access' value of false. So that's the reason I'm receiving 403. Still I'm lost, I don't know what I'm configuring wrong for the menu...