I have an action to set a Travel enabled , it works good but now I'd like to make it with ajax so I have installed FOSJsRoutingBundle but the problem is that I don't know how to write the ajax code.
Route
travel_enable:
path: /travel/enable/{id}
defaults: { _controller: "AppBundle:Travel:enable" }
options:
expose: true
Action
public function enableAction(Travel $travel)
{
$em = $this->getDoctrine()->getManager();
$travel->setEnabled(true);
$em->flush();
$referer = $this->getRequest()->headers->get('referer');
return $this->redirect($referer);
}
twig
<a href="{{ path('travel_enable', {'id': entity.id} ) }}" class="btn btn-xs btn-success" title="Enable"> Enable </a>
javascript
<script type="javascript">
// what to put here else
Routing.generate('travel_enable', { id: '...' });
</script>