I get "You are not authorized to access this page" when I try to load a view with Ajax I am trying to load a view with Ajax, showing it in a specific &lt;div&gt;. I always get the Ajax message, "You are not authorized to access this page." My code is the following one:

/**
* Implementation of hook_menu().
*/
function custom_api_menu() {
  $items['ajaxgettip/nojs/%'] = array(
    'page callback' =&gt; 'custom_api_test_ajax',
    'type' =&gt; MENU_CALLBACK,
    'access callback'   =&gt; TRUE,

      );
  $items['ajaxgettip/ajax/%'] = array(
     'delivery callback' =&gt; 'ajax_deliver',
     'access callback'   =&gt; TRUE,
  );
  return $items;
}


function custom_api_test_ajax($nid) {

   $viewName = 'tip';   
   $args = array($nid); 
   $displayId = 'block_1'; 
   $view = views_embed_view($viewName, $displayId, $args);
   //return drupal_json(array('test'=&gt;$res));
   ajax_deliver($view);     
}


I am creating a link as follows:

&lt;?php
    $link = array(
        '#type' =&gt; 'link',
        '#title' =&gt; t('something'),
        '#href' =&gt; 'ajaxgettip/ajax/114', #Hard coded nid at the end of path, just for testing
        '#ajax' =&gt; array(
            'wrapper' =&gt; 'ajax-response-goes-here',
            'method' =&gt; 'replace',
            'effect' =&gt; 'fade',
        ),
    );

$output = "&lt;div id='ajax-response-goes-here'&gt;Some HTML and stuff&lt;/div&gt;" . drupal_render($link);
print $output;
?&gt;


I don't have an idea about what I did wrong, and I have read a whole lot of documentation. Who can help me?
Try with page arguments in hook_menu:

function custom_api_menu() {
  $items['ajaxgettip/nojs/%'] = array(
      'page callback' =&gt; 'custom_api_test_ajax',
      'page arguments' =&gt; array(2),
      'type' =&gt; MENU_CALLBACK,
      'access callback' =&gt; TRUE,
  );
  $items['ajaxgettip/ajax/%'] = array(
      'delivery callback' =&gt; 'ajax_deliver',
      'page arguments' =&gt; array(2),
      'access callback' =&gt; TRUE,
  );
  return $items;
}