/***************************************************************
* Copyright notice
*
-* (c) 2008 Benjamin Mack <mack@xnos.org>
+* (c) 2008-2009 Benjamin Mack <mack@xnos.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* @return void
*/
public function setContentFormat($format) {
- if (t3lib_div::inArray(array('plain', 'xml', 'json', 'jsonhead', 'jsonbody'), $format)) {
+ if (t3lib_div::inArray(array('plain', 'xml', 'json', 'jsonhead', 'jsonbody', 'javascript'), $format)) {
$this->contentFormat = $format;
}
}
case 'json':
$this->renderAsJSON();
break;
+ case 'javascript':
+ $this->renderAsJavascript();
+ break;
case 'xml':
$this->renderAsXML();
break;
* @return void
*/
protected function renderAsError() {
+ header(t3lib_div::HTTP_STATUS_500 . ' (AJAX)');
header('Content-type: text/xml; charset='.$this->charset);
header('X-JSON: false');
die('<t3err>'.htmlspecialchars($this->errorMessage).'</t3err>');
echo $content;
}
}
+
+ /**
+ * Renders the AJAX call as inline JSON inside a script tag. This is useful
+ * when an iframe is used as the AJAX transport.
+ *
+ * @return void
+ */
+ protected function renderAsJavascript() {
+ $content = '<script type="text/javascript">
+ /*<![CDATA[*/
+
+ response = ' . json_encode($this->content) . ';
+
+ /*]]>*/
+ </script>';
+
+ header('Content-type: text/html; charset=' . $this->charset);
+ echo $content;
+ }
}