Bonjour,
J'essaye de faire un double ajax pour remplir 2 champs différents en fonction d'une même valeur. Je n'ai pas d'erreur, dans mon onglet Réseau les 2 variables passent bien. Mais l'un de mes 2 champs ne s'actualisent pas.
Je suis à la recherche d'une solution ou même mieux, d'une amélioration de mon système qui je pense est un peu crado.
La div qui se déclenche est donc "article_designationarticle" et celui qui ne fonctionne pas "article_prixunitaire". Merci d'avance.
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!-- PS  : c est un extrait, bien sûr tout cela est dans un tableau complet -->
              <td>
                <div class="article_designationarticle">
                  Le produit sera chargé ici
                </div>
              </td>
              <td>
                <div class="article_prixunitaire">
                  Le prix unitaire
                </div>
              </td>
<script>
  /* Affiche le nom de l'article en fonction de la référence sélectionnée */
  $(function(){
    $('#table_article').on('change', '.article_ref', function(){
      var article_ref = $(this).val();
      var article_designationarticle = $(this).parent().next().find('.article_designationarticle');
      $.ajax({
        url: "modal_header/Actions/ajax/inputdevis.php",
        method: "POST",
        data: { article_ref: article_ref }
      })
      .done(function( retour_html ) {
        article_designationarticle.html( retour_html );
      })
      .fail(function() {
        alert( "error facture creation ajax" );
      });       
    }); 
  });
    
  $(function(){
    $('#table_article').on('change', '.article_ref', function(){
      var article_ref = $(this).val();
      var article_prixunitaire = $(this).parent().next().find('.article_prixunitaire');
      $.ajax({
        url: "modal_header/Actions/ajax/getArticlePU.php",
        method: "POST",
        data: { article_ref: article_ref }
      })
      .done(function( retour_html ) {
        article_prixunitaire.html( retour_html );
      })
      .fail(function() {
        alert( "error facture creation ajax" );
      });       
    });
  });
  /* fin */
</script>
inputdevis.php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php include '../../../../Include/connect.php' ; 
 
    $article_ref  = (array_key_exists('article_ref', $_POST)) ? $_POST['article_ref']: NULL; 
    if ($article_ref) {
        $stmt = $bdd->prepare('
            SELECT * FROM produit
            WHERE produit_ref = :ref
        ');
        $stmt->bindValue(':ref', strtoupper($article_ref), PDO::PARAM_STR);
        $stmt->execute();
        if ($donnees = $stmt->fetch(PDO::FETCH_ASSOC)) { ?>
            <input class="form-control" type="text" value="<?php echo $donnees['produit_nom'] ?>" />     
        <?php 
        }
    }
getArticlePU.php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php include '../../../../Include/connect.php' ; 
 
    $article_ref  = (array_key_exists('article_ref', $_POST)) ? $_POST['article_ref']: NULL; 
    if ($article_ref) {
        $stmt = $bdd->prepare('
            SELECT * FROM produit
            WHERE produit_ref = :ref
        ');
        $stmt->bindValue(':ref', strtoupper($article_ref), PDO::PARAM_STR);
        $stmt->execute();
        if ($donnees = $stmt->fetch(PDO::FETCH_ASSOC)) { ?>
            <input class="form-control" type="text" value="<?php echo $donnees['produit_pu'] ?>" />     
        <?php 
        }
    }
?>
Merci d'avance