TYPO3 CMS  TYPO3_6-2
TYPO3\CMS\Core\Http\AjaxRequestHandler Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\AjaxRequestHandler:
TYPO3AJAX

Public Member Functions

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

Protected Member Functions

 renderAsError ()
 
 renderAsPlain ()
 
 renderAsXML ()
 
 renderAsJSON ()
 
 renderAsJavascript ()
 

Protected Attributes

 $ajaxId = NULL
 
 $errorMessage = NULL
 
 $isError = FALSE
 
 $content = array()
 
 $contentFormat = 'plain'
 
 $charset = 'utf-8'
 
 $requestCharset = 'utf-8'
 
 $javascriptCallbackWrap
 

Detailed Description

This file is part of the TYPO3 CMS project.

It is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, either version 2 of the License, or any later version.

For the full copyright and license information, please read the LICENSE.txt file that was distributed with this source code.

The TYPO3 project - inspiring people to share! Class to hold all the information about an AJAX call and send the right headers for the request type

Author
Benjamin Mack mack@.nosp@m.xnos.nosp@m..org

Definition at line 22 of file AjaxRequestHandler.php.

Constructor & Destructor Documentation

◆ __construct()

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

Sets the charset and the ID for the AJAX call due to some charset limitations in Javascript (prototype uses encodeURIcomponent, which converts all data to utf-8), we need to detect if the encoding of the request differs from the backend encoding, and then convert all incoming data (_GET and _POST) in the expected backend encoding.

Parameters
string$ajaxIdThe AJAX id

Definition at line 55 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$ajaxId, TYPO3\CMS\Core\Http\AjaxRequestHandler\$charset, and $GLOBALS.

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 102 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 76 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 122 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
boolean Whether this AJAX call had errors

Definition at line 166 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()

◆ renderAsError()

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

Renders the AJAX call in XML error style to handle with JS the "responseXML" of the transport object will be filled with the error message then

Returns
void

Definition at line 206 of file AjaxRequestHandler.php.

References die.

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

◆ 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
void

Definition at line 270 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$content, and $GLOBALS.

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

◆ renderAsJSON()

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

Renders the AJAX call with JSON evaluated headers note that you need to have requestHeaders: {Accept: 'application/json'}, in your AJAX options of your AJAX request object in JS

the content will be available

  • in the second parameter of the onSuccess / onComplete callback (except when contentFormat = 'jsonbody')
  • and in the xhr.responseText as a string (except when contentFormat = 'jsonhead') you can evaluate this in JS with xhr.responseText.evalJSON();
Returns
void

Definition at line 249 of file AjaxRequestHandler.php.

References TYPO3\CMS\Core\Http\AjaxRequestHandler\$content, and $GLOBALS.

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

◆ renderAsPlain()

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

Renders the AJAX call with text/html headers the content will be available in the "responseText" value of the transport object

Returns
void

Definition at line 219 of file AjaxRequestHandler.php.

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

◆ renderAsXML()

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

Renders the AJAX call with text/xml headers the content will be available in the "responseXML" value of the transport object

Returns
void

Definition at line 231 of file AjaxRequestHandler.php.

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

◆ setContent()

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

Overwrites the existing content with the first parameter

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 86 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 132 of file AjaxRequestHandler.php.

◆ 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 156 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 146 of file AjaxRequestHandler.php.

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

Member Data Documentation

◆ $ajaxId

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

◆ $charset

TYPO3\CMS\Core\Http\AjaxRequestHandler::$charset = 'utf-8'
protected

◆ $content

◆ $contentFormat

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

Definition at line 32 of file AjaxRequestHandler.php.

◆ $errorMessage

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

Definition at line 26 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 38 of file AjaxRequestHandler.php.

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

◆ $requestCharset

TYPO3\CMS\Core\Http\AjaxRequestHandler::$requestCharset = 'utf-8'
protected

Definition at line 36 of file AjaxRequestHandler.php.