Documentation

AjaxJson

\Bitrix\Main\Engine\Response\AjaxJson - JSON response methods.

By default, all responses from controllers \Bitrix\Main\Engine\Controller has standartized structure, handled by JS API [link=]BX.ajax.runAction[/link], [link=]BX.ajax.runComponentAction[/link]:

{
    "status": string,
    "data": mixed,
    "errors": array
}

Methods

Method Description Available from version
__construct(
   $data = null,
   $status = self::STATUS_SUCCESS,
   ErrorCollection $errorCollection = null
)
Class constructor. Parameters:
  • $data {mixed} Data, main portion of JSON-response. Responses must be converted in json-format by php mechanisms or by implementing one of interfaces:
    \JsonSerializable
    \Bitrix\Main\Type\Contract\Jsonable
    \Bitrix\Main\Type\Contract\Arrayable
  • $status {string} Response status. Success by default.
  • $errorCollection \Bitrix\Main\ErrorCollection Collection of errors. Empty by default.
createSuccess(
   $data = null
)
Create AjaxJson object with success status.
createError(
   ErrorCollection $errorCollection = null,
   $data = null
)
Create AjaxJson object with error status and allows passing collection of errors and data, if required.
createDenied(
   ErrorCollection $errorCollection = null,
   $data = null
)
Create AjaxJson object with denied status and allows passing collection of errors and data, if required.

© «Bitrix24», 2001-2024
Up