Ajax
Expose controller methods to the APPNETOS JavaScript AJAX API.
Ajax annotation
| Parameter | Type | Default | Behavior |
|---|---|---|---|
| user | bool | false (app) / true (admin) | Require an authenticated user; defaults depend on context. |
Marks a public controller method as callable by the APPNETOS AJAX runtime. The runtime validates AJAX token, method visibility, annotation and applicable user authentication. Data is accessed through the request controllers; the method is invoked without direct PHP arguments.
#[Ajax(user: true)]
public function loadDashboard(): string
{
return 'Dashboard content';
}
JavaScript client methods
| Parameter | Type | Default | Behavior |
|---|---|---|---|
| ajaxElement(class, method, elementId, data) | JavaScript | — | Insert text response into element.innerHTML. |
| ajaxFunction(class, method, callback, data) | JavaScript | — | Send text response to callback. |
| ajaxJson(class, method, callback, data) | JavaScript | — | Parse JSON response and invoke callback. |
| ajaxForm(class, method, callback, form) | JavaScript | — | Serialize form, invoke callback with text. |
| ajaxRequest(class, method, data, responseType, source) | JavaScript | — | Common fetch transport; responseType defaults to text. |
appnetos.ajaxElement('MyController', 'loadContent', 'content-container', {id: 123});
All client helpers use POST to the current page URL, sending class and method as form data with X-Appnetos-Ajax: 1 and an optional X-Appnetos-Ajax-Token header.