1 ajax_example_misc.inc ajax_link_response($type = 'ajax')

Callback for link example.

Takes different logic paths based on whether Javascript was enabled. If $type == 'ajax', it tells this function that ajax.js has rewritten the URL and thus we are doing an AJAX and can return an array of commands.

Parameters

string $type: Either 'ajax' or 'nojs. Type is simply the normal URL argument to this URL.

Return value

string|array If $type == 'ajax', returns an array of AJAX Commands. Otherwise, just returns the content, which will end up being a page.

Related topics

File

modules/examples/ajax_example/ajax_example_misc.inc, line 102
AJAX Miscellaneous Topics.

Code

function ajax_link_response($type = 'ajax') {
  if ($type == 'ajax') {
    $output = t("This is some content delivered via AJAX");
    $commands = array();
    // See ajax_example_advanced.inc for more details on the available commands
    // and how to use them.
    $commands[] = ajax_command_append('#myDiv', $output);
    $page = array('#type' => 'ajax', '#commands' => $commands);
    ajax_deliver($page);
  }
  else {
    $output = t("This is some content delivered via a page load.");
    return $output;
  }
}