[FLOW3-general] Ajaxable Actions / JSON as content-type
Ferdinand Kuhl
fcool at coolys.de
Sun Sep 18 17:25:04 CEST 2011
Hi David,
just add the following two lines to your controller:
protected $supportedFormats = array("html", "json");
protected $viewFormatToObjectNameMap = array(
"json" => "\TYPO3\FLOW3\MVC\View\JsonView",
"html" => "\TYPO3\Fluid\View\TemplateView"
);
And have a look at the really well documented JsonView-Class. (You can
configure the depth the objects are rendered)
The controller automatically detects what the request accepts, so if your
ajax-call (for example per jquery) explicitly asks for json, your controller
will answer with json.
Have a nice sunday,
Ferdinand
David Schoen wrote:
> Hello List,
>
> can anyone tell me how to make an action ajaxable? I would like to call
> an action with an JSON-request and would like to get the answer in JSON
> so I would have to change the content-type.
>
> Here is what I imagine:
>
> /**
> * Returns some json-object
> * @someAnnotationToSetTheReturnTypeToJSON
> * @return void
> */
> public function jsonAction() {
> ...
> return <someJsonObject>;
> }
>
> I can't find anything about that in the documentation or the
> blog-example. If you have any clue, tip or link, please answer :)
>
> Thanks in advance,
> David
More information about the FLOW3-general
mailing list