AJAX - Jet\AJAX
This is a very small but useful class that unifies and facilitates the generation of responses to requests and operations sent by the application frontend via XHR.
Method | Importance |
public static commonResponse( mixed $response_data, array $http_headers=[], int $http_code=200 ) : void | Generic JSON response
Parameters: - $response_dat
Any data that will be converted to JSON format. (Of course, the data must be JSON-convertible, meaning that the object classes must implement the PHP interface JsonSerializable. However, all relevant classes within Jet do this.)
- $http_headers
Optional HTTP response headers. See Jet\http_headers.
- $http_code
Optional HTTP response code. See Jet\Http_Headers.
|
public static operationResponse( bool $success, array $snippets=[], array $data=[] ) : void | Structured response to a specific operation (for example, form submission) in JSON format
Parameters: - $success
Indicates whether the operation succeeded/failed (bool).
- $snippets
The generated UI parts that need to be redrawn after the operation (whether it was successful or not - it's not critical). Effectively, this is an array containing pieces of HTML, and the keys of this array are the IDs of the HTML elements into which these pieces of HTML will be placed. Example: if a form is submitted via AJAX and it is not valid, the snippet can be that form, complete with values, but also error messages, hints and so on.
- $data
Any data that will be converted to JSON format. (Of course, the data must be JSON-convertible, meaning that the object classes must implement the PHP interface JsonSerializable. However, all relevant classes within Jet do this.)
|