i don't know what is wrong with this code, no errors but it doesn't work . what i want is when i click on a table row, a textarea should appear containing >all informations[web page][1] . *this is the twig file: 1. the script
<script>
function detailFunction() {
$('#ligneSelectionnee').click(function () {
id=$(this).val();
$.ajax({
type:"POST",
url:'http://localhost/randonneeweb/web/app_dev.php/recDetailAjax',
dataType:"json",
data:{id:id},
success : function (response) {
if (response!=null){
document.getElementById('nothing').style.display="none";
document.querySelector("#zoneDetail").innerHTML=response.view;
}
else{
document.getElementById('nothing').style.display="block";
}
}
})
})}
</script>
- the table row which should be selected
<tbody>
{% for m in reclamations %}
<tr id="ligneSelectionnee" value="{{ m.idreclamation }}" onclick="detailFunction()">
<td> {{ m.dateReclamation|date('Y-m-d') }}</td>
<td> {{ m.typereclamation }}</td>
<td> {{ m.sujetreclamation}}</td>
<td> {{ m.message }}</td>
</tr>
{% endfor %}
</tbody>
- the div where the details should appear
<div id="zoneDetail" style="margin-right: 20em">
</div>
**this is the function in the controller:
public function afficherDetailsAction(Request $request)
{echo "hellooo";
if($request->isXmlHttpRequest())
{
$id=$request->get('id');
$em=$this->getDoctrine()->getManager();
$reclamations=$em->getRepository('RandoPlusRandoBundle:Reclamation')->findBy(array('idreclamation'=>$id));
dump($reclamations);
if($reclamations!=null)
{
return new JsonResponse(
['view'=>$this->renderView('RandoPlusRandoBundle:Reclamation:detailAjax.html.twig',array('detail'=>$reclamations))],200
);
}
}
return new Response(null);
}
***the routing for the Ajax Function:
recDetailAjax:
path: /recDetailAjax
defaults: { _controller: RandoPlusRandoBundle:Reclamation:afficherDetails }
****and finally the twig used by Ajax to load details:
<label>Description</label></br><textarea>Date : {{ detail.dateReclamation }}</br>type:{{ detail.typereclamation }}</br>Sujet:{{ detail.sujetreclamation }}</br>Message:{{ detail.message }}</textarea>