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
| <script type="text/javascript" src="js/jquery.js">
<script src="js/jquery.min.js"></script>
<table id="tableau"></table>
<script>
var nbligne = 1;
function nouvelleligne(nbligne){
return '<form action="/" name="'+ nbligne +'" onKeyPress="ajouterligne($(this));" onclick="ajouterligne($(this));">' +
'<input name="id" type="text" />' +
'<input name="surf" type="text" />' +
'</form>';
}
// on crée la première ligne
var nouvelle_ligne = nouvelleligne(nbligne);
$(nouvelle_ligne).appendTo("#tableau");
function ajouterligne(ligne){
// Si c'est la dernière ligne
if(ligne.attr('name') == nbligne){
// On insert la nouvelle ligne
nbligne ++;
var nouvelle_ligne = nouvelleligne(nbligne);
$(nouvelle_ligne).insertAfter(ligne);
}
$(ligne).ajax({ //ICI
url:'traitement.php',
type: 'POST',
data: $(this).serialize(),
success: function(html) {
alert('ce que renvoie le fichier PHP' + html);
}
});
}
</script> |
Partager