All,
I am trying to implement AHAH in my custom module but some how it always throws HTTP 404 error. Can some one please look at my code and tell me whats going wrong here. I may have implemented completly wrong.

Thanks in advance

	$items[] = array(
	'path' => 'admin/get_states',
	'page callback' => address_states',
	'type' => MENU_CALLBACK,
	);

function address_states()
{
	return '<div>Some sample ahah content, from the server</div>';	  
}
$fields['address']['samples'] = array(
	      '#value' => '',
	      '#prefix' => '<div id="sample-ahah-samples">',
	      '#suffix' => '</div>',
    	);
$fields['address']['country'] = array(
	'#type' => 'select',
	'#title' => t('Country'),
	'#description' => t('Country.'),
	'#required' => TRUE,
	'#options' => $country,
	'#ahah' => array(
		'path' => 'admin/get_states',
	        'wrapper' => 'sample-ahah-samples',
	        'progress' => array('type' => 'bar', 'message' => t('Please wait...')),
	        'method' => 'replace',
	),

	);

Comments

darren.ferguson’s picture

If you are using drupal 6 the path is wrong it needs to be in the items as the key for the array as below:

$items['admin/get_states'] = array(
  'page callback' => 'address_states',
  'type' => MENU_CALLBACK,
  'access callback' => TRUE,
);

It changed in Drupal 6 compared to Drupal 5 and below.

Darren Ferguson
OpenBand / M.C.Dean

drupal_bineec’s picture

Thanks for the response, I did change the path but still it gives me the error.

error:
An error occured.
/drupal-6.2/admin/get_states
{Html here}

dutchslab’s picture

did you rebuild the menus, eg, run the 'Rebuild menus' command from the Dev module?

I feel your AHAH pain -- it should be easier . . .

geremy

drupal_bineec’s picture

I enabled/disabled the module and tested it, still it didnt help. How to run 'Rebuild menus' command?

darren.ferguson’s picture

Enabling and disabling will rebuild the menu for you.

Are you seeing anything in the request i.e if your using Firefox does firebug on the console display any information, maybe a 404 message or something.

Also do you have the base path for your site i.e. i use /d6 as my base path and not just the site name i.e. http://example.com/d6 so /d6 is the base path for my ajax requests and not http://example.com/

Darren Ferguson
OpenBand / M.C.Dean

drupal_bineec’s picture

I exposed the menu path and when I access it as a normal menu it works. It seems that when accessed from ahah it throws error.

newbuntu’s picture

seems to be weird error. If you try to access nonexistent link, drupal should simply comes back with "Page not found
The requested page could not be found."

If you get an http error, i wonder if it has to do with your system config. Like apache, permission etc? just a wild guess...

drupal_bineec’s picture

This resolved the error for me

drupal_json(array('status' => TRUE, 'data' => $output));

Thanks for everyones help.

herve76’s picture

Where did you add this line ?

pre911mindset’s picture

I know your problem is solved but in case someone comes upon this thread, you may want to see:

http://drupal.org/node/308310

drupal_bineec’s picture

AHAH handling code

cid = 'form_'. $_POST['form_build_id'];
	$cache = cache_get($cid, 'cache_form');
	if ($cache) {
	$form = $cache->data;
	}
	
	$form['address']['state'] = getStateSelectBox();
	cache_set($cid, $form, 'cache_form', $cache->expire);