I try to create controller that handles ajax requests.
I found out, that I have to add this to my TS config:
ajaxCall = PAGE
ajaxCall {
typeNum = 999
config.disableAllHeaderCode = 1
config.metaCharset = UTF-8
xhtml_cleaning = 0
admPanel = 0
10 = COA
10 < tt_content.list.20.registration_userregistration
}
And my controller looks like this:
/**
* JSONController
*/
class JSONController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* @var string
*/
protected $defaultViewObjectName = 'TYPO3\\CMS\\Extbase\\Mvc\\View\\JsonView';
/**
* action test
*
* @return string
*/
public function testAction() {
$this->view->assign('value', "001");
}
}
This works, I get a blank page with "001" on it. But if I look at the source, there are 4 empty lines, and "001" is in the 5th line.
-empty-
-empty-
-empty-
-empty-
"001"
I have no idea why...
Okay, I got it...
I included a file with some functions named user.php
In this file there were empty lines after the ?> tag. These empty lines were the problem. I deleted them and now everything works fine. :)
I don't get, why are you using some view for rendering JSON ???
Of course you should set
Content-type: application/json
- where do you prefer - in your TS or directly in the action before return;Other clue: maybe it's caused by tt_content (just guesing), for JSON actions it's best to include them directly via Bootstrap, first register new FE plugin in your
ext_localconf.php
:And modify your TS:
(don't forget to change Yourextname and VENDORNAME for your own, also clear the system cache)
Finally: Check all your files and make sure that there's no empty lines before
<?php
and after?>
(the best option is to remove?>
from each file - and let PHP to terminate script at the end of file). Also it can be fixed in the source of TYPO3 as described in other naswer.