|
Publicité | ||||||||||||||||||||||
|
|
#1 (permalink) |
|
Membre Confirmé
![]() Date d'inscription: février 2007
Messages: 252
|
bonjour a tous,
j'ai decouvert quelque chose d'etrange avec Ajax et Javascript. Voila j'ai un code brded.php tres simple Code :
<?php echo '<select name="brule">'; echo '<option value=1>brule1</option>'; echo '<option value=2>brule2</option>'; echo '<option value=3>brule3</option>'; echo '<option value=4>brule4</option>'; echo '<option value=5>brule5</option>'; echo '</select>'; ?> Code :
<script> var bUniqueRowID = 0; function getXhr(){ var xhr = null; if(window.XMLHttpRequest) // Firefox and others xhr = new XMLHttpRequest(); else if(window.ActiveXObject){ // Internet Explorer try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { // XMLHttpRequest not supported by your browser alert(" Your browser does not support XMLHTTPRequest objects..."); xhr = false; } return xhr } /** * method called when the user clicks on the button */ function gobr(){ var xhr = getXhr() // We defined what we gonna do with the response xhr.onreadystatechange = function(){ // We do somthing once the server's response is OK if(xhr.readyState == 4 && xhr.status == 200){ // Retrieve <table> ID and create a <tbody> element // Retrieve <table> ID and create a <tbody> element var tbl = document.getElementById("brtable"); var tblBody = document.createElement("tbody"); var row = document.createElement("tr"); bUniqueRowID += 1; var cell_1 = document.createElement("td"); cell_1.align="center"; cell_1.valign="center"; var cell_2 = document.createElement("td"); cell_2.align="center"; cell_2.valign="center"; var cell_3 = document.createElement("td"); cell_3.align="center"; cell_3.valign="center"; // Create the first cell which is a select var cell1 = document.createElement("div"); cell1.innerHTML=xhr.responseText; cell_1.appendChild(cell1); //Create the second cell a checked box var cell2=document.createElement("input"); cell2.type="checkbox"; cell2.name="brdedicated"; cell_2.appendChild(cell2); // Create the third cell which is a button var cell3=document.createElement("input"); cell3.type="button"; cell3.value="Delete" cell3.onclick=delRowbr; cell_3.appendChild(cell3); // add cells to the row row.appendChild(cell_1); row.appendChild(cell_2); row.appendChild(cell_3); // add the row to the end of the table body tblBody.appendChild(row); // put the <tbody> in the <table> tbl.appendChild(tblBody); // Rename cells with the row index var ind=row.rowIndex; var liste_bname = row.getElementsByTagName("input"); var selectname = row.getElementsByTagName("select"); for(i=0; i < liste_bname.length; i++){ if (/*(liste_bname[i].name == "brule")|| */ (liste_bname[i].name == "brdedicated")){ liste_bname[i].name = liste_bname[i].name + "_" + ind; } } selectname[0].name = selectname[0].name + "_" + ind; alert(ind); // sets the border attribute of tbl to 2; tbl.setAttribute("border", "2"); } } xhr.open("GET","brded.php",true); xhr.send(null); } function delRowbr(){ var i= this.parentNode.parentNode.rowIndex; document.getElementById('brtable').deleteRow(i); } </script> <form method="post"> <table align="center" border = "2" cellspacing ="0" cellpadding="3" id="brtable"> <tr><td><b>Business Rule Type:</b></td> <td><b>Dedicated:</b></td><td><input type="button" Name= "Ajouterbr" Value="Ajouter BR" onclick="gobr()"></td></tr> </table> </form> Code :
echo '<option value=6>brule6</option>';
pour que cette option apparaisse, il faut que je ferme cette page et que je relance localhost. et ainsi l'option 6 apparait. Qu'en pensez vous? Est-ce normal ? Merci d’avance. Merci Billy |
|
|
|
|
|
#4 (permalink) | |
![]() Date d'inscription: mars 2002
Localisation: Au coeur de la Nébuleuse de la Rainette
Messages: 22 624
|
http://www.innerhtml.saimal.fr/
dasn la partie retour tu crées déja au moyen du DOM les elements parents... ne t'arretes pas en si bon chemin ! fais pluto generer un objet json à ta page php sur le retour un simple eval et ensuite tu crées dynamiquement ton select
__________________
Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts ) Citation:
Votre post a trouvé une réponse qui vous satisfait ? Alors n'oubliez pas le Tag ![]() réalisations web (developpeur et/ou infographiste et/ou chef de projet: www.saftair.com| www.ouestisol.fr | www.sebemex.fr | www.sistac-alizay.fr | www.planet-languages.com | www.acoustishop.fr | www.litt.fr |
|
|
|
|
|
#5 (permalink) |
![]() Date d'inscription: octobre 2007
Localisation: Paris
Messages: 489
|
C'est un phénomène de cache navigateur non ? Tu as essayé de passer un paramètre (qui change à chaque fois) à ta requete AJAX ?
Code :
xhr.open("GET","brded.php?dt=" + new Date().getTime(),true);
__________________
on ne dit pas "ça ne marche pas" on dit "je suis incapable de faire fonctionner correctement les outils mis à ma disposition" |
|
|
|
|
|
#6 (permalink) | |
![]() Date d'inscription: mars 2002
Localisation: Au coeur de la Nébuleuse de la Rainette
Messages: 22 624
|
le cache peut jouer aussi en effet
suffit de mettre un header no cache dans la page php ou comme proposé passer un timestamp lors du send
__________________
Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts ) Citation:
Votre post a trouvé une réponse qui vous satisfait ? Alors n'oubliez pas le Tag ![]() réalisations web (developpeur et/ou infographiste et/ou chef de projet: www.saftair.com| www.ouestisol.fr | www.sebemex.fr | www.sistac-alizay.fr | www.planet-languages.com | www.acoustishop.fr | www.litt.fr |
|
|
|
|
|
#7 (permalink) |
![]() Date d'inscription: février 2006
Localisation: Normandie
Messages: 3 346
|
simple problème de cache ;-)
ajoute un pragma no cache dans ton fichier php je te renvois ici : http://fr.php.net/manual/fr/function.header.php
__________________
est ton ami fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes Premier ministre du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts ) |
|
|
|
|
|
#9 (permalink) | |
|
Membre Confirmé
![]() Date d'inscription: février 2007
Messages: 252
|
Citation:
Thanks
|
|
|
|
|
|
|
#11 (permalink) | |
|
Membre Confirmé
![]() Date d'inscription: février 2007
Messages: 252
|
Citation:
|
|
|
|
|
|
|
![]() |
||
Etrange JS et Ajax
|
||
| Outils de la discussion | |
|
|