Recherche Instantanée (filtre)
Bonjour, je suis en train de doter mon application d'une recherche instantanée, sorte de filtre par expression entrée dans un champ de formulaire. J'utilise naturellement la méthode ajax et jQuery mais à priori j'ai une erreur quand la requête est envoyée. Dans la console de Firebug, j'ai l'erreur suivante :
Dans mon code j'ai :
Deux actions, la 1ère qui affiche un formulaire de recherche et la 2ème qui traite l'information entrée :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| /**
* Displays a form to create a new Tache tache.
*
* @Route("/filtre", name="tache_filtre")
* @Template("TacheBundle:Tache:filtrer.html.twig")
*/
public function champFiltreAction()
{
$form = $this->createForm(new RechercheType());
return array(
'form' => $form->createView()
);
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| /**
* Trouver les taches filtrées.
*
* @Route("/find_filtre", name="tache_apres_filtre")
* @method("post")
*/
public function filtrerAction(Request $request)
{
$filtreForm = $this->createForm(new RechercheType());
if ($request->getMethod() == 'POST') {
$filtreForm->bindRequest($request);
$data = $filtreForm->getData();
$motcle=$data['value'];
if ($filtreForm->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$taches = $em->getRepository('TacheBundle:Tache')->getSearchList($motcle);
}
}
return $this->container->get('templating')->renderResponse('TacheBundle:Tache:liste.html.twig', array('taches' => $taches));
} |
Le code Ajax :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
$(document).ready(function(){
$("#tacherecherche_motcle").keyup(function(){
var filtre = $("#tacherecherche_motcle").val();
// alert(filtre);
$.ajax({
type : 'POST',
url : 'http://localhost/public/sortirplus/web/app_dev.php/tache/find_filtre',
data: {'filtre': filtre},
success: function(server_response){
$("#resultat_filtre").html(server_response).show();
}
});
});
}); |
Et la vue :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
{% extends 'TacheBundle::layout.html.twig' %}
{% block body_bundle %}
<h1>Filtrer par</h1>
<form id="form_filtre" action="{{ path('tache_filtre') }}" method="post">
{{ form_widget(form) }}
</form>
<div id="resultat_filtre">
</div>
{% endblock %}
{% block javascripts %} <!-- BLOC JAVASCRIPT -->
{{ parent() }}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="{{ asset('bundles/tache/js/filtre.js') }}" type="text/javascript"></script>
{% endblock %} |
Mon code est loin d'être bon mais en tant que débutant j'aimerais juste que ça marche. Si vous pouvez m'aider je serais reconnaissant, merci beaucoup!