Friday 25 May 2012

AJAX on a link with no form.

<?php
$link = array(
'#type' => 'link',
'#title' => t('something'),
'#href' => 'some/path',
'#ajax' => array(
'callback' => 'some_callback_function',
'wrapper' => 'ajax-response-goes-here',
'method' => 'replace',
'effect' => 'fade',
),
// Using the onload below is entirely optional; It's just included as
// a reminder of an easy way to add extra simple jQuery tricks.
'#attributes' => array(
'onload' => "jQuery('something-to-hide').hide();",
),
);
$output = "<div id='ajax-response-goes-here'></div>Some HTML and stuff" . drupal_render($link);
?>
trigger an AJAX callback using the enter key when focusing on an element, add keypress = TRUE to the #ajax array, e.g.:
<?php
$form['element'] = array(
'#type' => 'textfield',
'#title' => 'Title',
'#ajax' => array(
'callback' => '...',
'keypress' => TRUE,
),
);
?>

No comments:

Post a Comment