title: category filter with ajax and symfony
body: <p>On a website made with symfony, I would like the user being able to display questions of a category by clicking on a button.</p>
  
  <p>For now, clicking on a category returns the all page. And, I don't have any errors in my console.</p>
  
  <p>Here's the code :</p>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>function helpFilterAction() {
      $(".helpCategoryFilter").on('click', function (e) {
          e.preventDefault();
          var $this = $(this);
          var category = $(this).text().trim();
          $.ajax({
              url: $this.attr('action'),
              type: $this.attr('method'),
              data: 'category='+category,
              success: function(data) {
                  if (!$.trim(data)){
                      $('#faq_list').html("&lt;p class='content__text'&gt;Nothing&lt;/p&gt;");
                  }
                  else{
                      $('#faq_list').html(data);
                      $(".loading").hide();
                  }
              }
          });
      });
  }
  </code></pre>
  
  <p><strong>FaqController.php</strong></p>
  
  <pre><code>/**
  * Search for faq entities with categories
  *
  * @Route("/category", name="faq_category")
  * @Method({"POST"})
  */
  public function helpFilterAction(Request $request)
  {
      if ($request-&gt;isXmlHttpRequest()) {
          $category = '';
          $category = $request-&gt;get('category');
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          if ($category != '') {
              $qb = $this-&gt;createQueryBuilder('a');
              $qb-&gt;add('select', 'a');
              $qb-&gt;leftJoin('a.category', 'c');
              $qb-&gt;where('c.name LIKE :category');
              $qb-&gt;setParameter('category', $category);
  
              $query = $qb-&gt;getQuery();
              $faqs = $query-&gt;getResult();
          } else {
              $faqs = $em-&gt;getRepository('AppBundle:Faq')-&gt;findAll();
          }
  
          return $this-&gt;render(
              'faq/list.html.twig',
              array(
                  'faqs' =&gt; $faqs,
              )
          );
      } else {
          return $this-&gt;indexAction();
      }
  }
  </code></pre>
  
  <p><strong>Faq.php</strong></p>
  
  <pre><code>/**
   * Faq
   *
   * @ORM\Table(name="faq")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\FaqRepository")
   */
  class Faq
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="question", type="string", length=255)
       */
      private $question;
  
      /**
       * @var string
       *
       * @ORM\Column(name="answer", type="text")
       */
      private $answer;
  
      /**
       * @ORM\ManyToOne(targetEntity="FaqCategory", inversedBy="faqs")
       */
      private $category;
  
      ...
  }
  </code></pre>
  
  <p><strong>FaqCategory.php</strong></p>
  
  <pre><code>/**
   * FaqCategory
   *
   * @ORM\Table(name="faq_category")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\FaqCategoryRepository")
   */
  class FaqCategory
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=255, unique=true)
       */
      private $name;
  
      /**
       * @ORM\OneToMany(targetEntity="Faq", mappedBy="category")
       */
      private $faqs;
  
      ...
  }
  </code></pre>
  
  <p><strong>index.html.twig</strong></p>
  
  <pre><code>{% extends 'base.html.twig' %}
  
  {% block body %}
      &lt;div class="linearBg site-pusher help--pusher"&gt;
          &lt;div class="content"&gt;
              &lt;div class="content__title"&gt;
                  &lt;h2 class="content__titleText"&gt;Aide&lt;/h2&gt;
              &lt;/div&gt;
              &lt;div class="content__text mobile-not-displayed"&gt;
                  &lt;p class="content__textText"&gt;Vous retrouverez-ici les nombreux conseils et informations concernant les différents services qu’offrent notre plateforme&lt;/p&gt;
              &lt;/div&gt;
  
              &lt;form id="faq_search" action="{{ path('faq_search') }}" method="post" class="searchForm--help"&gt;
                  &lt;input id="appbundle_research_faq_keyword" type="search" name="search" placeholder="Comment réserver mon billet ?" class="searchForm__input--help"&gt;
                  &lt;button type="submit" class="searchForm__submit--help"&gt;CHERCHER&lt;/button&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  
          &lt;div id="helpCategoriesFilter" class="helpCategoriesFilter"&gt;
              {% for faqcategory in faqcategorys %}
                  &lt;div class="helpCategoryFilterContent"&gt;
                      &lt;div class="helpCategoryFilter"&gt;
                          &lt;div class="helpCategoryFilterTitle"&gt;
                              {{ faqcategory.name }}
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="helpCategoryFilterBg"&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              {% endfor %}
          &lt;/div&gt;
  
          &lt;div class="loading"&gt;&lt;/div&gt;
          &lt;div id="faq_list" class="content content__help"&gt;
              {% include 'faq/list.html.twig' %}
          &lt;/div&gt;
  
      &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong>list.html.twig</strong></p>
  
  <pre><code>{% for faq in faqs %}
      &lt;div class="helpContent"&gt;
          &lt;div id="helpCard1" class="helpContent__card"&gt;
              &lt;div class="helpContent__title"&gt;
                  {{ faq.question }}
              &lt;/div&gt;
              &lt;div class="helpContent__chevron"&gt;
                  &lt;img src="{{ asset('img/icons/Chevron.svg') }}" alt=""&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div id="helpContent1" class="helpContent__text not-displayed"&gt;
              {{ faq.answer }}
          &lt;/div&gt;
      &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>Could someone help me with this?</p>