Documentation

AJAX

Table of Contents

Functions

ajax_permission_denied()  : void
Returns a standard AJAX response for unauthorised access
ajax_send_response()  : void
Send AJAX response back to the client together with the appropriate HTTP status code
ajax_send_text_response()  : void
Send AJAX text/html response back to the client together with the appropriate HTTP status code
ajax_response_ok()  : array<string|int, mixed>
Builds the correct response expected for a success request where there is data to return (e.g getting search results)
ajax_response_fail()  : array<string|int, mixed>
Builds the correct response expected for failures.
ajax_response_ok_no_data()  : array<string|int, mixed>
Builds the correct response expected for a success request where there is no data to return (e.g when deleting a record)
ajax_unauthorized()  : void
Returns a standard AJAX response for unauthorised access with a 401 HTTP status code
ajax_build_message()  : array<string|int, mixed>
Builds a message to be used in an AJAX response

Functions

ajax_permission_denied()

Returns a standard AJAX response for unauthorised access

ajax_permission_denied() : void

The function will return a 401 HTTP status code.

ajax_send_response()

Send AJAX response back to the client together with the appropriate HTTP status code

ajax_send_response(int $code, array<string|int, mixed> $response) : void
Parameters
$code : int

HTTP status code for this response

$response : array<string|int, mixed>

Response data (@see other ajax_response_* functions for expected structure)

ajax_send_text_response()

Send AJAX text/html response back to the client together with the appropriate HTTP status code

ajax_send_text_response(int $code, string $response) : void
Parameters
$code : int

HTTP status code for this response

$response : string

Response data (text/html)

ajax_response_ok()

Builds the correct response expected for a success request where there is data to return (e.g getting search results)

ajax_response_ok(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

Data to be returned back to the client

Return values
array<string|int, mixed>

ajax_response_fail()

Builds the correct response expected for failures.

ajax_response_fail(array<string|int, mixed> $data) : array<string|int, mixed>

When a call is rejected due to invalid data or call conditions, the response data key contains an object explaining what went wrong, typically a hash of validation errors.

Parameters
$data : array<string|int, mixed>

Provides details of why the request failed. If the reasons for failure correspond to POST values, the response objects' keys SHOULD correspond to those POST values. If generic, use message key instead (@see ajax_build_message() ).

Return values
array<string|int, mixed>

ajax_response_ok_no_data()

Builds the correct response expected for a success request where there is no data to return (e.g when deleting a record)

ajax_response_ok_no_data() : array<string|int, mixed>
Return values
array<string|int, mixed>

ajax_unauthorized()

Returns a standard AJAX response for unauthorised access with a 401 HTTP status code

ajax_unauthorized() : void

ajax_build_message()

Builds a message to be used in an AJAX response

ajax_build_message(string $msg) : array<string|int, mixed>
Parameters
$msg : string

An end-user message explaining what happened (as a generic message for fails or part of errors)

Return values
array<string|int, mixed>

Returns a message

On this page

Search results