I am developing a web application with Symfony, but I have some problems with Ajax.
I would like to press some button with id (1,2,3,4...) and dynamicaly (with ajax) search in my db some stuff who are related with those ids.
My javascript code :
appP08.controls.btnZone.on('click', function(){
var ZoneID = $(this).attr('id');
var ZoneName = $(this).text();
alert(ZoneID);
$.ajax({
url: "/recor/circuit",
type: "POST",
data: {
ZoneID: ZoneID
},
success: function(data){
$('#divCircuit').html(data);
$('#zoneChoice').text(' - ' + ZoneName);
appP08.controls.divZone.hide();
}
});
});
When I press the button, Ajax is executed and I see the alert, so Jquery works well. But after that nothing happens.
I have created a route :
mk_reappro_production_circuit:
path: /recor/circuit
defaults: {_controller: MKReapproProductionBundle:Appli:circuit }
methods: [post]
And the controller :
public function circuitAction(Request $req){
$req = $this->getRequest();
if ($req->isXMLHttpResult()){
$id = $req->request->get('ZoneID');
if($id != null){
$repository = $this->getDoctrine()->getManager()->getRepository('MKReapproProductionBundle:Circuit');
$listCircuits = $repository->findAll($id);
return $this->render('MKReapproProductionBundle:Appli:circuit.html.twig', array(
'listCircuits' => $listCircuits
));
}
}
}
The view :
{% extends "MKReapproProductionBundle::layout.html.twig" %}
{% block mk_appli_train_body_circuit %}
<div id="divCircuit">
{% for circuit in listCircuits %}
<button class="btn btn-success" name="btnZone">
{{ circuit.name }}
</button>
{% endfor %}
</div>
{% endblock %}
What should I do to display this button ?
In the Symfony Toolbar there is just this :
