AJAX link error (form API) I have an AJAX link and a callback function. The problem is that when I click the link an error is thrown. 

I have absolutely no idea where did I make an error, the debug information unfortunately doesn't help.

As I understand the AJAX and Form API, the TSTDiv should be replaced with the TST link therefore two links should be visible on the page, right? The problem is, it not only doesn't work, but even throws an (really unhelpful) error.

The callback function / menu hook work fine (correct output is rendered when you access the URL (of the AJAX request) directly).

Code:

function HOOK_menu() {
  $items = array();

  $items['groups_hierarchy_load_more'] = array(
    'page callback' =&gt; '_fmg_agh_hierarchy_load_more',
    'access callback' =&gt; 'user_access',
    'access arguments' =&gt; array('Can view all groups'),
    'type' =&gt; MENU_CALLBACK,
  );
...

  $page_array['l'] = array(
    '#type' =&gt; 'link',
    '#title' =&gt; 'TEST',
    // Note the /nojs portion of the href - if javascript is enabled,
    // this part will be stripped from the path before it is called.
    '#href' =&gt; 'groups_hierarchy_load_more/' . '5' . '/nojs',
    '#ajax' =&gt; array(
      'wrapper' =&gt; 'TSTDiv',
      'method' =&gt; 'replace',
    ),
  );

  $page_array['d'] = array(
    '#type' =&gt; 'markup',
    '#prefix' =&gt; '&lt;div id="TSTDiv"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  );
...

function _fmg_agh_hierarchy_load_more($group_id, $ajax) {
  $page_array = array();

  $page_array['tst']['data'] = array(
    '#type' =&gt; 'link',
    '#title' =&gt; 'TST',
    // Note the /nojs portion of the href - if javascript is enabled,
    // this part will be stripped from the path before it is called.
    '#href' =&gt; 'groups_hierarchy_load_more/' . 'TST' . '/nojs',
  );

  return $page_array;
}


Error:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /drupal7/?q=groups_hierarchy_load_more/5/ajax
StatusText: OK
ResponseText: 
localhost
@import url("http://localhost/drupal7/modules/system/system.base.css?n3277e");
...
While I still don't know where the problem is (it should work this way) I've found a solution. 

Instead returning the whole $page_array in callback function and hoping that Drupal will understand it and replace the div specified in '#ajax' =&gt; array('wrapper' =&gt; 'TSTDiv',... property of the link with it you can simply use ajax commands and 'return' something like this:

$commands[] = ajax_command_replace('#TSTDiv', render($page_array));
$page = array('#type' =&gt; 'ajax', '#commands' =&gt; $commands);
ajax_deliver($page);


And vuala it works just fine (and looks more professional at the same time!).

Would still appreciate and answer why the original approach didn't work, though.

BTW: I didn't know the AJAX commands before.