bonjour
comme étant débutant en AJAX je veux envoyer une valeur avec ajax puisfaire les calculs sur cette variable
voici le code :
le fichier data.php :
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> function submitForm() { if (window.XMLHttpRequest) // Objet standard { xhr = new XMLHttpRequest(); // Firefox, Safari, ... } else if (window.ActiveXObject) // Internet Explorer { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open( "POST", "data.php", true); xhr.send("v=1"); xhr.onreadystatechange = function() { if(xhr.readyState == 4) { if(xhr.status == 200) document.getElementById("dyn2").innerHTML = "Received:" + xhr.responseText; else document.getElementById("dyn2").innerHTML= xhr.status; } } } </script> </head> <body> <FORM method="POST" name="formajax" action=""> <INPUT type="text" name="dyn1" value=""> <INPUT type="BUTTON" value="Envoyer" ONCLICK="submitForm()"> <div id="dyn2" > </div> </FORM> </body> </html>
il m'affiche une erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <?php echo "val = ".$_POST["v"]; ?>
Notice: Undefined index: v in D:\Projets\websites\htdocs\formation AJAX\data.php on line 2
val =
Partager