Bonjour
j'ai un probleme assez bizare. J'au une page formulaire.html qui fait appel à Demande.php à travers xmlhttprequest. Le comportement est tres bizare surtout que je ne suis pas un expert du web.
1. quand je rempli le formulaire, le status est tj =0
2. quand je laisse le formuliare vide, les deux premiers appuis sur le button submit me donne un status 0, puis, apres 3 ou 4 clique, je recoit les données XML.
D'apres mon analyse (modeste) le probleme est dans l'envoie de données avec la methode GET.
Pouvez vous me renseigner SVP
Merci
Formulaire.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 !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>Document sans nom</title> <style type="text/css"> <!-- .Style1 { color: #990033; font-style: italic; font-weight: bold; } --> </style> <script type="text/javascript" language="javascript"> var http_request = false; function makeRequest() { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } paramters="?cin="+document.form.cin.value; http_request.onreadystatechange = alertContents;//listener http_request.open('GET', "Demande.php" + paramters , true); http_request.send(null); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { alert (http_request.responseText); var xmldoc = http_request.responseXML; var root = xmldoc.getElementsByTagName('root').item(0); document.getElementById("amani").innerHTML = 'votre numero de carta d identit� est ' +root.getElementsByTagName("num")[0].firstChild.nodeValue +'<br>votre score est ' + root.getElementsByTagName("score")[0].firstChild.nodeValue +'<br>votre rang est ' +root.getElementsByTagName("rang")[0].firstChild.nodeValue ; for (var iNode = 0; iNode < root.childNodes.length; iNode++) { var node = root.childNodes.item(iNode); } } else { alert('There was a problem with the request . '+http_request.status); } } } </script> </head> <body> <div align="center" class="Style1">formulaire d'insciption</div> <form name="form" method="GET" action="#" > <table width="35%" border="0" align="center"> <tr> <td width="34%"><div align="right">cin:</div></td> <td width="66%"><input name="cin" type="text" /></td> </tr> <tr> <td><div align="right">nom:</div></td> <td><input name="nom" type="text" /></td> </tr> <tr> <td><div align="right">prenom:</div></td> <td><input name="prenom" type="text" /></td> </tr> <tr> <td><div align="right">e_mail: </div></td> <td><input name="email" type="text" /></td> </tr> <tr> <td><div align="right">passwd:</div></td> <td><input name="passwd" type="password" /></td> </tr> <tr> <td><div align="right">verif passwd:</div></td> <td><input name="passwd1" type="password" /></td> </tr> <tr> <td><div align="right">moy mi3:</div></td> <td><input name="moy" type="text" /></td> </tr> <tr> <td><div align="right">note linux:</div></td> <td><input name="notlinux" type="text" /></td> </tr> <tr> <td><div align="right">note miniprojet:</div></td> <td><input name="notemp" type="text" /></td> </tr> <tr> <td><div align="right">note java:</div></td> <td><input name="notejava" type="text" /></td> </tr> <tr> <td><input name="envoyer" type="submit" value="Envoyer" onclick="javascript:makeRequest();" /></td> <td><input name="annuler" type="reset" value="annuler"/></td> </tr> </table> <div id="amani"> </div> <p> </p> </form> </body> </html>
Demande.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 <?php if(isset ($_GET["cin"]) ){ $e=10; $resultat=$_GET["cin"]*2; $rang=4; echo "<root>"; echo "<num>".$e."</num>"; echo "<score>".$resultat."</score>"; echo "<rang>".$rang."</rang>"; echo "</root>"; } ?>
Partager