function ajax_link_response

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

1 string reference to 'ajax_link_response'
ajax_example_menu in ajax_example/ajax_example.module
Implements hook_menu().

File

ajax_example/ajax_example_misc.inc, line 102

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;
    }
}