TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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

Deprecated:
since TYPO3 v8, will be removed in TYPO3 v9

Definition at line 26 of file core/Classes/Http/AjaxRequestHandler.php.

Constructor & Destructor Documentation

__construct (   $ajaxId)

Sets the ID for the AJAX call

Parameters
string$ajaxIdThe AJAX id

Definition at line 69 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$ajaxId.

Member Function Documentation

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 107 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$content.

getAjaxID ( )

Returns the ID for the AJAX call

Returns
string The AJAX id

Definition at line 79 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$ajaxId.

getContent (   $key = '')

Returns the content for the ajax call

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

Definition at line 128 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$content.

isError ( )

Checks whether an error occurred during the execution or not

Returns
bool Whether this AJAX call had errors

Definition at line 176 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$isError.

Referenced by AjaxRequestHandler\render(), and AjaxRequestHandler\setError().

render ( )

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

Returns
ResponseInterface|NULL

Definition at line 186 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\isError(), and AjaxRequestHandler\renderAsJavascript().

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
InvalidArgumentException

Definition at line 302 of file core/Classes/Http/AjaxRequestHandler.php.

References GeneralUtility\makeInstance().

Referenced by AjaxRequestHandler\render().

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 90 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$content.

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 139 of file core/Classes/Http/AjaxRequestHandler.php.

References ArrayUtility\inArray().

setError (   $errorMsg = '')

Sets an error message and the error flag

Parameters
string$errorMsgThe error message
Returns
void

Definition at line 165 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\isError().

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 154 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$javascriptCallbackWrap.

Member Data Documentation

$ajaxId = null
protected
$contentFormat = 'plain'
protected

Definition at line 51 of file core/Classes/Http/AjaxRequestHandler.php.

$errorMessage = null
protected

Definition at line 36 of file core/Classes/Http/AjaxRequestHandler.php.

$isError = false
protected

Definition at line 41 of file core/Classes/Http/AjaxRequestHandler.php.

Referenced by AjaxRequestHandler\isError().

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

Definition at line 56 of file core/Classes/Http/AjaxRequestHandler.php.

Referenced by AjaxRequestHandler\setJavascriptCallbackWrap().