Skip to content

Instantly share code, notes, and snippets.

@martsie
Created January 25, 2017 11:06
Show Gist options
  • Save martsie/cabf7f3940e61609dbbe12c3e3a41746 to your computer and use it in GitHub Desktop.
Save martsie/cabf7f3940e61609dbbe12c3e3a41746 to your computer and use it in GitHub Desktop.
Ajax callback for Drupal AJAX commands article
<?php
/**
* AJAX callback that prints hello world underneath our link.
*/
function MY_CUSTOM_MODULE_ajax_callback() {
// Define a new array to hold our AJAX commands.
$ajax_commands = array();
// Create a new AJAX command that replaces the #page text with our own text.
$ajax_commands[] = ajax_command_after('#my-special-link', 'Hello world');
// Return our commands in JSON.
ajax_deliver(array('#type' => 'ajax', '#commands' => $ajax_commands));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment