集体数据和jQuery

You can usually use something like this:

<form action="example.php" method="POST">
<input type="text" name="file_name[]">
<input type="text" name="file_name[]">
<input type="text" name="file_name[]">

to collect data under the same name, and access it in PHP like:

$file_name = $_POST["file_name"];
echo $file_name[0]; //first occurrence
echo $file_name[2]; //third occurrence

but when it comes to generating dynamic fields with jQuery, like this:

$("#example_table").append("<tr><td><input type="text" name="file_name[]"></td></tr>");

and submitting it with standard submit button within POST form, the outcome differs. Only the last occurrence gets passed but the array indexes represent consecutive letters of such, not exact, indicated field as above.

The question is, why and how to fix it?

You can use single quote instead of double quote for file_name. Might be this is useful to you.

$("#example_table").append("<tr><td><input type='text' name='file_name[]'></td></tr>");

You have to remove another double quotes from the html string. You have two ways for that

1. $("#example_table").append("<tr><td><input type=\"text\" name=\"file_name[]\"></td></tr>");

2. $("#example_table").append('<tr><td><input type="text" name="file_name[]"></td></tr>');

Maybe this will help.

So, the problem is solved. It was all about using double quotes instead of single ones. Thank you for your participation and support.