Bonjour,
je debute avec ajax ,et j'ai un petit probléme concernant les listes liés
à vrai dire la premiere liste se rempli correctement depuis la base de donnée mais lorsque je choisi une option la 2 éme liste ne se remplis pas
merci d'avance pour votre aide
la page php responsable de l'envoi les données
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 <?php session_start();?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" > <head> <title>Manipulation des listes de choix</title> </head> <script type='text/javascript' src='oXHR.js'></script> <script type='text/javascript'> var xhr=null; function request(callback) { xhr=getXHR(); if(xhr.readyState != 0) { xhr.abort(); } xhr.onreadystatechange = function() { if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { callback(xhr.responseXML); document.getElementById("loader").style.display = "none"; } else if (xhr.readyState < 4) { document.getElementById("loader").style.display = "inline"; } }; var value = encodeURIComponent(document.getElementById('editorsSelect').options[document.getElementById('editorsSelect').selectedIndex].value); xhr.open("POST", "reqListe.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("IdEditor=" + value); } function test(sData) { var p = sData.getElementsByTagName("soft"); alert(p.length); for(var i=0;i<p.length;i++) { var option = document.createElement("option"); var text = document.createTextNode(p[i].getAttribute('name')); option.setAttribute('value',p[i].getAttribute('id')); option.appendChild(text); document.getElementById('softwaresSelect').appendChild(option); } } </script> <body> <div id="programBox"> <p id="editors"> <select id="editorsSelect" onchange="request(test);"> <option value="none">Selection</option> <?php $bdd= new PDO('mysql:host=localhost;dbname=test','root',''); $reponse=$bdd->query('SELECT * FROM ajax_example_editors ORDER BY name') or die(print_r($bdd->errorInfo())); while($rep=$reponse->fetch()) { echo "\t\t\t\t<option value=\"" . $rep["id"] . "\">" . $rep["name"] . "</option>\n"; } $reponse->closeCursor(); ?> </select> <span id="loader" style="display: none;"><img src="loading.gif" alt="loading" /></span> </p> <p id="softwares"> <select id="softwaresSelect"></select> </p> </div> </body> </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 <html> <body> <?php header("Content-Type: text/xml"); if(isset($_POST['IdEditor'])){ $bdd= new PDO('mysql:host=localhost;dbname=test','root',''); $reponse=$bdd->prepare('SELECT * FROM ajax_example_softwares where idEditor=? ORDER BY name') or die(print_r($bdd->errorInfo())); $reponse->execute(array($_POST['IdEditor'])); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; echo "<root>"; while($rep=$reponse->fetch()) { echo "<soft id=\"" .$rep["id"]."\" name=\"" .$rep["name"]."\"/>"; } $reponse->closeCursor(); echo "</root>"; } ?> </body> </html>
Partager