title: Controller must return a response in Symfony2
body: <p>I have an ajax call in my code. What I want to achieve with the call works fine. I want to delete some records from the database which is actually deleted when the method is called via ajax but as in symfony method it must return a response and thats why when the method is executed its gives me the error </p>
  
  <p>My Ajax call is </p>
  
  <pre><code>  $.ajax({
          type: "POST",
          data: data,
          url:"{{ path('v2_pm_patents_trashpatents') }}",
          cache: false,
          success: function(){
          document.location.reload(true);
          }
      });
  </code></pre>
  
  <p>And the method that is executed is </p>
  
  <pre><code> public function trashpatentAction(Request $request){
      if ($request-&gt;isXmlHttpRequest()) {
          $id = $request-&gt;get("pid");
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
          $patent_group = $em-&gt;getRepository('MunichInnovationGroupPatentBundle:PmPatentgroups')-&gt;find($id);
          if($patent_group){
              $patentgroup_id = $patent_group-&gt;getId();
              $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
              $patents = $em-&gt;getRepository('MunichInnovationGroupPatentBundle:SvPatents')
              -&gt;findBy(array('patentgroup' =&gt; $patentgroup_id));
              if($patents){
                  foreach($patents as $patent){
                      if($patent-&gt;getIs_deleted()==false){
                          $patent-&gt;setIs_deleted(true);
                          $em-&gt;flush();
                      }
                  }
              }
              $patent_group-&gt;setIs_deleted(true);
              $em-&gt;flush();
          }
          else{
              $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
              $patent = $em-&gt;getRepository('MunichInnovationGroupPatentBundle:SvPatents')-&gt;find($id);
              if ($patent) {
                  $patent-&gt;setIs_deleted(1);
                  $em-&gt;flush();
              }
          }
          return true;
      }
  }
  </code></pre>
  
  <p>How can I successfully return from this method ?
  Any ideas? Thanks</p>