S
S
semki0962017-04-02 15:04:26
symfony
semki096, 2017-04-02 15:04:26

How to handle Ajax request in symfony?

I'm trying to send a form in symfony (POST method) using Ajax. As far as I understand, symphony has its own framework - it is required to connect Request and Response. Here is an example controller (it works), but it does not use Request directly. However, if I disable use Request, there will be a 500 server error. Why is that?

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\JsonResponse;

public function ajaxAction()    
{       
        return new JsonResponse(array('data' => 'this is a json response'));
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question