Skip to content

classes_base_ajaxresponse.class

Daniel Spors edited this page Dec 19, 2023 · 3 revisions

Classes in file base/ajaxresponse.class.php

class AjaxResponse

Helper class to easily create standard AJAX responses.

AddScript

Allows addition of scripts to responses. Sometimes it is useful to add JS codes for immediate execution. In plain HTML request this would be done with for example Control() which adds the script to the parent pages init method, but for AJAX requests we need to go this way.

Definition: public function AddScript($script)

Returns: self

Parameters:

  • array|string $script script code or array of script codes to be added.

Error

Return an error. If $abort_handling is true the clietside error handling will not be polled

Definition: public static function Error($message, $abort_handling=false)

Returns: AjaxResponse The created response

Parameters:

  • string $message The error message

  • bool $abort_handling Abort clientside success/error handling

Js

Return just script code to be executed clientside immetiately. If $abort_handling is true the clientside success/error handling will not be polled

Definition: public static function Js($script=false, $abort_handling=false)

Returns: AjaxResponse The created response

Parameters:

  • mixed $script JS code as string or array

  • bool $abort_handling Abort clientside success/error handling

Json

Return data JSON formatted ($data can be anything!).

Definition: public static function Json($data=null)

Returns: AjaxResponse The created response

Parameters:

  • mixed $data Data to be passed out

None

This is a valid Noop return.

Definition: public static function None($abort_handling=false)

Returns: AjaxResponse The created response

Parameters:

  • bool $abort_handling Abort clientside success/error handling

Redirect

Let the client redirect.

Definition: public static function Redirect($controller, $event, $data)

Returns: AjaxResponse The created response

Parameters:

  • mixed $controller The controller to be loaded (can be Renderable or string)

  • string $event The event to be executed

  • mixed $data Optional data to be passed (string or array)

Reload

Let the client reload the current page.

Definition: public static function Reload()

Returns: AjaxResponse The created response

Render

INTERNAL Renders the response for output.

Renderable

Return a Controller (with full init-code).

Definition: public static function Renderable(Renderable $content, $force_dependency_loading=null)

Returns: AjaxResponse The created response

Parameters:

  • Renderable $content Content to be passed out

  • bool $force_dependency_loading If false, stops automatic JS/CSS dependency search and delivery

Text

Return a plain text.

Definition: public static function Text($text=false)

Returns: AjaxResponse The created response

Parameters:

  • string $text Text to be passed out
Clone this wiki locally