title: How to submit form ajax in symfony2?
body: <p>I am about to submit my form Using Ajax,i have successfully submit my form using <em>POST</em> but don't know how to use Ajax with <em>Symfony</em></p>
  
  <p><strong>builform</strong></p>
  
  <pre><code>    $builder-&gt;add('name', 'text', array('constraints' =&gt; array(new NotBlank()), 'attr' =&gt; array('placeholder' =&gt; 'Name')))
          -&gt;add('gender', 'choice', array('empty_value' =&gt; 'Select Gender', 'constraints' =&gt; array(new NotBlank()), 'choices' =&gt; \AppBundle\Entity\Records::$gender_list, "required" =&gt; true))
          -&gt;add('dateOfBirth', 'birthday', array('label' =&gt; 'Date Of Birth','required'=&gt;true))
          -&gt;add('image_path', 'file', array('label' =&gt; ' ','required'=&gt;false, 'data_class' =&gt; null, 'constraints'=&gt;array(new Assert\File(                                             array('mimeTypes'=&gt;$mime_types, 'maxSize'=&gt;'2048k' )))))
          -&gt;add('country_of_birth', 'entity', array('empty_value' =&gt; 'Country of Birth',
              'class' =&gt; 'AppBundle\Entity\Location',
              'property' =&gt; 'country',
              'label' =&gt; 'Country of Birth'
          ))
          -&gt;add('religion', 'entity', array('empty_value' =&gt; 'Select Religion',
              'class' =&gt; 'AppBundle\Entity\Religion',
              'property' =&gt; 'name',
              'label' =&gt; 'Religion'
          ));
  </code></pre>
  
  <p><strong>Action</strong></p>
  
  <pre><code>        $success = false;
          $record_rep = new \AppBundle\Entity\Records();
          $form = $this-&gt;createForm(new \AppBundle\Form\AddPersonType(), $record_rep);
  
          if ($this-&gt;getRequest()-&gt;getMethod() == 'POST') {
              $form-&gt;submit($request);
              if ($form-&gt;isValid()) {
                  $data = $form-&gt;getData();
                  $file = $data-&gt;getImagePath();
                  $image = $file-&gt;getClientOriginalName();
  
                  $new_image_name = $this-&gt;hanldeUpload($image, $file);
                  $this-&gt;savetoDB($data, $record_rep, $new_image_name);
                  $success = true;
              }
          }
          return $this-&gt;render('AppBundle:Homepage:add_person_form.html.twig', array('form' =&gt; $form-&gt;createView(), 'success'=&gt;$success ));
      }
  </code></pre>