Bonjour,
je débute avec jquery et je voulais exploiter ajax :
quand je clique sur le bouton addition, je suis censé avoir le résultat ds le p avec id resultat.
Ca marche pas, voici mon code. Merci :
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 <html> <head> <title>Test smarty</title> <script type="text/javascript" src="../js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#add').click($.post("../calcul.php",{ a: $('#a').value, b: $('#b').value }, function(data){ $('#resultat').html(data); }) ); }); </script> </head> <body> <center> <br/><br/><br/> <form> a : <input type="text" name="a" id="a"/><br/> b : <input type="text" name="b" id="b"/><br/> <input type="button" name="submit" value="Addition" id="add"/> </form> <p id="resultat"><!--{$resultat}--></p> </center> </body> </html>
mon fichier calcul.php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 <?php $a = $_POST['a']; $b = $_POST['b']; echo $a + $b ?>
Partager