How to send serialize form data using JQuery if the input element is an array

后端 未结 14 669
庸人自扰
庸人自扰 2020-12-16 15:16

I have this piece of code in my PHP code:

while ($row = mysqli_fetch_assoc($result))
{
    extract($row);
    echo \"\";
    echo \"

        
14条回答
  •  自闭症患者
    2020-12-16 16:09

    If you have to post that array only and not other input fields, this is a clean and quick solution:

    var selectedbooks = $('book_form input[name^="bookArray["]').serialize();
    alert (selectedbooks); 
    

    Explaination:

    The selector ^= selects all elements with a name attribute value starting with 'bookArray', the open square bracket '[' makes sure the element is the array we want to serialize and not just a variable starting with the string 'bookArray'.

提交回复
热议问题