TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Http\AjaxRequestHandler Class Reference

Public Member Functions

 __construct ($ajaxId)
 
 getAjaxID ()
 
 setContent ($content)
 
 addContent ($key, $content)
 
 getContent ($key='')
 
 setContentFormat ($format)
 
 setJavascriptCallbackWrap ($javascriptCallbackWrap)
 
 setError ($errorMsg='')
 
 isError ()
 
 render ()
 

Protected Member Functions

 renderAsJavascript ()
 

Protected Attributes

 $ajaxId = null
 
 $errorMessage = null
 
 $isError = false
 
 $content = []
 
 $contentFormat = 'plain'
 
 $javascriptCallbackWrap
 

Detailed Description

Class to hold all the information about an AJAX call and send the right headers for the request type

Definition at line 25 of file AjaxRequestHandler.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Http\AjaxRequestHandler::__construct (   $ajaxId)

Sets the ID for the AJAX call

Parameters
string$ajaxIdThe AJAX id

Definition at line 68 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$ajaxId.

Member Function Documentation

◆ addContent()

TYPO3\CMS\Core\Http\AjaxRequestHandler::addContent (   $key,
  $content 
)

Adds new content

Parameters
string$keyThe new content key where the content should be added in the content array
string$contentThe new content to add
Returns
mixed The old content; if the old content didn't exist before, FALSE is returned

Definition at line 106 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$content.

◆ getAjaxID()

TYPO3\CMS\Core\Http\AjaxRequestHandler::getAjaxID ( )

Returns the ID for the AJAX call

Returns
string The AJAX id

Definition at line 78 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$ajaxId.

◆ getContent()

TYPO3\CMS\Core\Http\AjaxRequestHandler::getContent (   $key = '')

Returns the content for the ajax call

Returns
mixed The content for a specific key or the whole content

Definition at line 127 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$content.

◆ isError()

TYPO3\CMS\Core\Http\AjaxRequestHandler::isError ( )

Checks whether an error occurred during the execution or not

Returns
bool Whether this AJAX call had errors

Definition at line 175 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$isError.

Referenced by TYPO3\CMS\Core\Http\AjaxRequestHandler\render(), and TYPO3\CMS\Core\Http\AjaxRequestHandler\setError().

◆ render()

TYPO3\CMS\Core\Http\AjaxRequestHandler::render ( )

Renders the AJAX call based on the $contentFormat variable and exits the request

Returns
ResponseInterface|NULL

Definition at line 185 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$content, TYPO3\CMS\Core\Http\AjaxRequestHandler\isError(), TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance(), and TYPO3\CMS\Core\Http\AjaxRequestHandler\renderAsJavascript().

◆ renderAsJavascript()

TYPO3\CMS\Core\Http\AjaxRequestHandler::renderAsJavascript ( )
protected

Renders the AJAX call as inline JSON inside a script tag. This is useful when an iframe is used as the AJAX transport.

Returns
ResponseInterface
Exceptions

Definition at line 301 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

Referenced by TYPO3\CMS\Core\Http\AjaxRequestHandler\render().

◆ setContent()

TYPO3\CMS\Core\Http\AjaxRequestHandler::setContent (   $content)

Overwrites the existing content with the data supplied

Parameters
array$contentThe new content
Returns
mixed The old content as array; if the new content was not an array, FALSE is returned

Definition at line 89 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$content.

◆ setContentFormat()

TYPO3\CMS\Core\Http\AjaxRequestHandler::setContentFormat (   $format)

Sets the content format for the ajax call

Parameters
string$formatCan be one of 'plain' (default), 'xml', 'json', 'javascript', 'jsonbody' or 'jsonhead'
Returns
void

Definition at line 138 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Utility\ArrayUtility\inArray().

◆ setError()

TYPO3\CMS\Core\Http\AjaxRequestHandler::setError (   $errorMsg = '')

Sets an error message and the error flag

Parameters
string$errorMsgThe error message
Returns
void

Definition at line 164 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\isError().

◆ setJavascriptCallbackWrap()

TYPO3\CMS\Core\Http\AjaxRequestHandler::setJavascriptCallbackWrap (   $javascriptCallbackWrap)

Specifies the wrap to be used if contentFormat is "javascript". The wrap used by default stores the results in a variable "response" and adds <script>-Tags around it.

Parameters
string$javascriptCallbackWrapThe javascript callback wrap to be used
Returns
void

Definition at line 153 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$javascriptCallbackWrap.

Member Data Documentation

◆ $ajaxId

TYPO3\CMS\Core\Http\AjaxRequestHandler::$ajaxId = null
protected

◆ $content

◆ $contentFormat

TYPO3\CMS\Core\Http\AjaxRequestHandler::$contentFormat = 'plain'
protected

Definition at line 50 of file AjaxRequestHandler.php.

◆ $errorMessage

TYPO3\CMS\Core\Http\AjaxRequestHandler::$errorMessage = null
protected

Definition at line 35 of file AjaxRequestHandler.php.

◆ $isError

TYPO3\CMS\Core\Http\AjaxRequestHandler::$isError = false
protected

◆ $javascriptCallbackWrap

TYPO3\CMS\Core\Http\AjaxRequestHandler::$javascriptCallbackWrap
protected
Initial value:
= '
<script type="text/javascript">
/*<![CDATA[*/
response = |;
/*]]>*/
</script>
'

Definition at line 55 of file AjaxRequestHandler.php.

Referenced by TYPO3\CMS\Core\Http\AjaxRequestHandler\setJavascriptCallbackWrap().