Symfony ajax probleme d'affichage
Bonjour,
voila je rencontre un probleme avec mon code, en fait, je veux selectionné dans mon select box et ca affiche les informations concernant la selection, je me suis retourné vers Ajax pour mon select box, j'ai fait comme ceci
Ajax
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
function showSelect(val) {
if (val == "") {
document.getElementById("liste").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("liste").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","{{ path('AppBundle:Client:facture', {'idclient' : idclient}) }}?idclient="+val,true);
xmlhttp.send();
}
} |
Controller
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
public function clientAction()
{
$em = $this->getDoctrine()->getManager();
$dql = "Select c.num from AppBundle:Client c";
$query = $em->createQuery($dql);
$client = $query->getResult();
return $this->render('AppBundle:Client:client.html.twig', array('client' => $client
// ...
));
}
public function factureAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$find = $request->request->get('idclient');
$dql = "select c.idclient, c.nom, c.adresse, f.quantite, f.prixT
from AppBundle:Client c inner join AppBundle:Facture f with c.idclient = f.idclient
WHERE c.idclient = :idclient";
$query = $em->createQuery($dql)
->setParameter('idclient', $find);
$facture = $query->getResult();
return $this->render('AppBundle:Client:facture.html.twig', array('facture' => $facture
));
} |
Client.html.twig
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
{% extends "::base.html.twig" %}
{% block body %}
<div class="row">
<div class="container">
<div class="col-md-6">
<label>Numeros Client :</label>
<select onchange="showSelect(this.value);">
<option></option>
{% for client in client %}
<option name="idclient">{{ client.num }}</option>
{% endfor %}
</select>
</div>
<div class="col-md-6" align="right">
<div id="liste">
{{ render(controller('AppBundle:Client:facture')) }}
</div>
</div>
</div>
</div>
{% endblock %} |
facture.html.twig
Code:
1 2 3 4 5 6 7 8 9
|
{% block body %}
{% for facture in facture %}
<h5>{{ facture.nom }}</h5>
<h5>{{ facture.adresse }}</h5>
<h5>{{ facture.quantite }}</h5>
<h5>{{ facture.prixT }}</h5>
{% endfor %}
{% endblock %} |
Le probleme ce que y a rien d'afficher coté facture, aide moi a decouvrir ce qui cloche s'il vous plait merci,