weixin_33696106 2015-02-19 12:09 采纳率: 0%
浏览 33

集体数据和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?

  • 写回答

3条回答 默认 最新

  • weixin_33671935 2015-02-19 12:13
    关注

    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>");
    
    评论

报告相同问题?