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' => '_fmg_agh_hierarchy_load_more',
'access callback' => 'user_access',
'access arguments' => array('Can view all groups'),
'type' => MENU_CALLBACK,
);
...
$page_array['l'] = array(
'#type' => 'link',
'#title' => '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' => 'groups_hierarchy_load_more/' . '5' . '/nojs',
'#ajax' => array(
'wrapper' => 'TSTDiv',
'method' => 'replace',
),
);
$page_array['d'] = array(
'#type' => 'markup',
'#prefix' => '<div id="TSTDiv">',
'#suffix' => '</div>',
);
...
function _fmg_agh_hierarchy_load_more($group_id, $ajax) {
$page_array = array();
$page_array['tst']['data'] = array(
'#type' => 'link',
'#title' => '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' => '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");
...