Utilisation AJAX pour recherche dans BDD : bouton submit inactif
michgoarin
Messages postés10Date d'inscriptionvendredi 2 mai 2008StatutMembreDernière intervention 8 décembre 2015
-
7 déc. 2015 à 22:50
Mimiste
Messages postés1149Date d'inscriptionsamedi 17 mai 2008StatutMembreDernière intervention 6 mars 2016
-
18 déc. 2015 à 11:15
Bonjour à tous,
Ami(e)s expert, voici une question pour vous :
J'ai un formulaire qui me permet d'effectuer une recherche dans une BDD en temps réel.
Cette recherche me permettrait de faire une sortie de stock. Le seul problème : au chargement des lignes le bouton "submit" est inactif.
Pourriez vous m'expliquer pourquoi ? Auriez vous une solution ?
Vous l'aurez compris, il y a deux fichiers :
- Le formulaire,
- La résultat.
<title>Accueil</title> <script type="text/javascript"> $(document).ready( function() { // détection de la saisie dans le champ de recherche $('#q').keyup( function(){ $field = $(this); $('#results').html(''); // on vide les resultats $('#ajax-loader').remove(); // on retire le loader
// on commence à traiter à partir du 2ème caractère saisie if( $field.val().length > 1 ) { // on envoie la valeur recherché en GET au fichier de traitement $.ajax({ type : 'GET', // envoi des données en GET ou POST url : 'sortie_materiel_search.php' , // url du fichier de traitement data : 'q='+$(this).val() ,// données à envoyer en GET ou POST beforeSend : function() { // traitements JS à faire AVANT l'envoi $field.after('<img src="ajax-loader.gif" alt="loader" id="ajax-loader" />'); // ajout d'un loader pour signifier l'action }, success : function(data){ // traitements JS à faire APRES le retour d'ajax-search.php $('#ajax-loader').remove(); // on enleve le loader $('#results').html(data); // affichage des résultats dans le bloc } }); } }); });
</script> </head>
<body id="top">
<h2>Sortie Article</h2> <div class="recherche_article"> <!--debut du formulaire--> <form class="ajax" action="bdc.php" method="get"> <p> <label for="q">Rechercher un article</label> <input type="text" name="q" id="q" /> </p> </form> </fieldset> <!--fin du formulaire--> </div> <!--preparation de l'affichage des resultats--> <div id="results"></div> <hr style="height: 3px; color: #ffffff; width: 100%; border: 1px dashed #000;"></hr> </body> </html>
La recherche et le résultat :
<?php // Connexion à la base de données include("menu//chiens.php"); $result = $bdd->query("SELECT*FROM `stock` WHERE REF_INTERNE LIKE '%". safe( $_GET['q'] ) ."%' OR REFERENCE_MARQUE_PROPOSEE LIKE '%". safe( $_GET['q'] ) ."%' OR GRANDE_FAMILLE LIKE '%". safe( $_GET['q'] ) ."%' OR FAMILLE LIKE '%". safe( $_GET['q'] ) ."%' OR DESIGNATION LIKE '%". safe( $_GET['q'] ) ."%' ORDER BY REF_INTERNE ASC"); $i=0; // début du tableau echo '<div class="article-result">'; echo ("<table width='780'>\n"); echo ("<tr>"); echo ("<td style='width:55px; font-size:10px;'><strong>REF INTERNE</strong></td>"); echo ("<td style='width:290px; font-size:10px;'><strong>DESIGNATION</strong></td>"); echo ("<td style='width:120px; font-size:10px;'><strong>FOURNISSEUR</strong></td>"); echo ("<td style='width:90px; font-size:10px;'><strong>REF FOURNISSEUR</strong></td>"); echo ("<td style='width:90px; font-size:10px;'><strong>MARQUE</strong></td>"); echo ("<td style='width:45px; font-size:10px;'><strong>STOCK</strong></td>"); echo ("<td style='width:45px; font-size:10px;'><strong>PRIX (HT)</strong></td>"); echo ("<td style='width:110px; font-size:10px; text-align:center;'>QTT</td>"); echo ("<td width='5'></td>"); echo ("<td width='20' align='center'><strong>Valider</strong></td>"); echo ("</tr>"); // On récupère tout le contenu de la table while($row = $result->fetch()){ //Affichage des résultats echo ("<tr bgcolor='".( ($i++ % 2 == 0) ? '#dddddd' : '#eeeeee' )."'>"); echo ("<td style='width:55px; font-size:11px;'>".$row['REF_INTERNE']."</td>"); echo( "<td style='width:290px; font-size:11px;'>".$row['DESIGNATION']."</td>"); echo( "<td style='width:120px; font-size:11px;'>".$row['FOURNISSEUR']."</td>"); echo( "<td style='width:90px; font-size:11px;'>".$row['REFERENCE_MARQUE_PROPOSEE']."</td>"); echo( "<td style='width:90px; font-size:11px;'>".$row['MARQUE_PROPOSEE']."</td>"); echo( "<td style='width:45px; font-size:11px;'>".$row['STOCK']."</td>"); echo( "<td style='width:45px; font-size:11px;'>".$row['PRIX_UNITAIRE']."</td>"); // Début du formulaire de sortie d'article echo( "<form action='traitement_sortie_article.php' method='post' name='traitement_sortie_article' id='traitement_sortie_article'>"); echo ("<td align='center'><input type='number' name='qtt_saisie' id='qtt_saisie' min='0'/></td>"); echo( "<td> <input type='hidden' name='ref_interne' value='".$row['REF_INTERNE']."' id='ref_interne'> <input type='hidden' name='id_article' value='".$row['ID']."' id='id_article'>"); echo( "<td align='center'><input type='submit' name='selectionner' value='S'></td>"); echo ('</form>'); echo ('</tr>'."\n");