TYPO3  7.6
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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 = array()
 
 $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 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 68 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 106 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$content, and elseif.

getAjaxID ( )

Returns the ID for the AJAX call

Returns
string The AJAX id

Definition at line 78 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 127 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 175 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 185 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 301 of file core/Classes/Http/AjaxRequestHandler.php.

References $response, and 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 89 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 138 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 164 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 153 of file core/Classes/Http/AjaxRequestHandler.php.

References AjaxRequestHandler\$javascriptCallbackWrap.

Member Data Documentation

$ajaxId = null
protected
$content = array()
protected
$contentFormat = 'plain'
protected

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

$errorMessage = null
protected

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

$isError = false
protected

Definition at line 40 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 55 of file core/Classes/Http/AjaxRequestHandler.php.

Referenced by AjaxRequestHandler\setJavascriptCallbackWrap().