Prev |  | Next

## 3.2. Miscellaneous

### 3.2.1. ajax_<call>

(Phorum 5 >= 5.2.8)

This hook allows module writers to implement calls for the Phorum Ajax layer.
The "call" argument from the Ajax argument array is used to construct the name of the hook that will be called. For example for the call "sayhello" the called hook will be `call_sayhello`
A call implementation should always be using the provided functions `phorum_ajax_return()` and `phorum_ajax_error()` to return data to the client. Because these functions will call `exit` after they are done, hook functions that implement an Ajax call stop page execution and do not return like other hook functions. Only if the hook function decides for some reason that the Ajax call is not to be handled by the module, it can return the Ajax argument array.

Call time:

Just before ajax.php tries to find a built-in handler script for an Ajax call. Therefore, this hook can also be used to override core Ajax call implementations. We strongly discourage doing so though.

Hook input:

The Ajax argument array

Hook output:

The same array as the one that was used for the hook call argument.

Example code:

    function phorum_mod_foo_ajax_sayhello($ajax_args)
    {
        // An optional name=.... argument can be used in the request.
        $name = phorum_ajax_getarg('name', 'string', 'Anonymous Person');

        // This will return a JSON encoded string to the client.
        phorum_ajax_return("Hello, $name");
    }

For this hook implementation, a GET based URL to fire this Ajax call could look like `http://example.com/ajax.php?call=sayhello,name=JohnDoe`.

Prev | Up | Next
| Home |