POSTs not transmitted
POSTs not transmitted
Hello,
I have problems with a jQuery script.
At the beginning, the script displays 2 forms.
When we click or write in one of the forms, then:
- it adds a new line only if the clicked one was the last line,
- it POST forms data of the line into a PHP file.
But my PHP file does not receive any POST. $_POST result is :Array ()
Here are my complete HTML file (1) and PHP file (2):
- <script type="text/javascript" src="js/jquery.js">
<script src="js/jquery.min.js"></script>
<table id="tab"></table>
<script>
var nbline = 1;
function newline(nbline){
return '<form action="/" method="post" name="f'+ nbline +'" onKeyPress="addline($(this));" onclick="addline($(this));">' +
'<input name="id" type="text" />' +
'<input name="surf" type="text" />' +
'</form>';
}
// first line creation
var new_line = newline(nbline);
$(new_line).appendTo("#tab");
function addline(line){
// if last line
if(line.attr('name') == ('f'+nbline)){
// then we insert a new line
nbline ++;
var new_line = newline(nbline);
$(new_line).insertAfter(line);
}
$.ajax({
url:'traitement.php',
type: 'POST',
data: $(this).serialize(),
success: function(codehtml) {
alert('What the PHP return : ' + codehtml);
}
});
}
</script>
- <?php
print_r($_POST);
?>
Can't find what is happening.
Thanks a lot...