[TYPO3-mvc] ajax, output json_encode()

Alexander Stehlik alexander.stehlik at gmail.com
Mon Nov 24 13:06:26 CET 2014


Hi Muriel,

you need to return the JSON string:

return json_encode($ajaxResponse);

Then you will not need a template any more.

Cheers,
Alex

Am 24.11.2014 um 12:46 schrieb Muriel le Pair:
> Hi,
>
> I would like to send an ajax request and return it to the page as json.
>
> /**
> * action ajaxsubmit
> *
> * @return void
> */
> public function ajaxsubmitAction() {
>
>      //$this->view->assign('forms', $forms);
>
>      $ajaxResponse = array(
>          'success' => false,
>          'message' => "test"
>      );
>      json_encode($ajaxResponse);
>
> }
>
> If I call the action with JavaScript TYPO3 is nagging that the template
> is missing what is strange because I did not assign a view
> ($this->view->assign('forms', $forms);).
>
> If I add an empty template Ajaxsubmit.html to the template folder, the
> error will disappear and the content of the template is returned to my
> page.
>
> But I would like the json resonse instead.
>
> The strange thing is that it works in another extension. I can't
> remember that I needed to do something special to prevent the template
> to be renderd and output the json with json_encode().
>
> What am I missing?
>
> --
> kind regards,
>
> Muriel le Pair
>


-- 
Alexander Stehlik
alexander.stehlik at gmail.com


More information about the TYPO3-project-typo3v4mvc mailing list