I have this dropdwonlist, this numbers are votes. In the below code I've put the controller's function where I manage votes. This works fine, with its route-action-template; my question is, how I can do the same but with JQuery-AJAX code without refreshing the page?
The default value of the dropdown list is votacion.votCalificacion
which is the value of the vote in the database
This is the dropdownlist of votes:
<form id="post">
<select id="cd-dropdown" class="cd-select">
<option value="-1" selected>{{ voto.votCalificacion }}</option>
<option>-</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select>
</form>
This is the controller's function to manage votes:
public function gestionarVotoAction($pysStr, $votCalificacion)
{
$em = $this->getDoctrine()->getManager();
$pys = $em->getRepository('PYSBundle:Pys')->findPys($pysStr);
$usuario = $this->get('security.context')->getToken()->getUser();
$voto = $em->getRepository('UsuarioBundle:Usuario')->findVoto($usuario, $pys);
if(!$voto)
{
$voto = new Voto($usuario, $pys);
}
if ($votCalificacion == "-")
{
$em->remove($voto);
}
else
{
$voto->setVotCalificacion($votCalificacion);
$voto->setVotFecha(new \DateTime("now"));
$em->persist($voto);
}
$em->flush();
return $this->redirect($this->generateUrl('usuario_pelicula', array('pysStr' => $pysStr)));
}