Bonjour,
J'essaye tant bien que mal d'utiliser AJAX avec Jquery, cependant je bloque pas mal sur le moment où il faut envoyer les variables au formulaire PHP, et récupérer le résultat sur la page courante.
Voici ma fonction JS sur ma page courante :
Code : 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 $(document).ready(function(){ $("form#submit").submit(function() { // we want to store the values from the form input box, then send via ajax below var datedebut = $("#from").val(); var datefin = $("#to").val(); var jours = $("#jours").val(); var horairedebut = $("#valueA").val(); var horairefin = $("#valueB").val(); var labo = $("#labo").val(); var corres = $("#corres").val(); //J'ai testé un alert ici, toutes les variables sont BONNES $.ajax({ type: "POST", url: "db.php", data: "datedebut="+ datedebut +"& datefin="+ datefin +"& jours="+ jours +"& horairedebut="+ horairedebut +"& horairefin="+ horairefin +"& labo="+ labo +"& corres="+ corres, beforeSend : function() { // traitements JS à faire AVANT l'envoi $('#results').after('<img src="img/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 } }); return false; }); });
Et mon fichier php :
Comme vous pouvez le voir, pour le moment je cherche juste à renvoyer les deux variables $jours et $datedebut sur ma page courante. (La requête SQL viendra après, il faut déjà que je comprenne cette partie...)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?php $datedebut = htmlspecialchars(trim($_POST['datedebut'])); $datefin = htmlspecialchars(trim($_POST['datefin'])); $jours = htmlspecialchars(trim($_POST['jours'])); $horairedebut = htmlspecialchars(trim($_POST['horairedebut'])); $horairefin = htmlspecialchars(trim($_POST['horairefin'])); $labo = htmlspecialchars(trim($_POST['labo'])); $corres = htmlspecialchars(trim($_POST['corres'])); echo $datedebut; echo $jours; ?>
Ma page courante affiche l'image du loader, donc ça bloque pour le "success". (car l'image ne disparaît pas)
Cordialement,
Logarithmix
Partager