Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Pass form array data with Jquery ajax

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #27275

    Hello.

    I have a form that allows you to post several names at once.

    Here is the input field.

    Code:

    Then using Jquery I want to pass the data to send.php without reloading the page so I use:

    Code:
    $.post(action, { email: $(‘#email’).val() }

    But how do I pass an array value through the ajax? I know it needs to pass it as "name[]" but I’m having trouble setting that up in the jQuery. Something like this will fail:

    Code:
    $.post(action, { name[]: $(‘.name’).val() }

    Thank you.

    #68375
    BaylorRae
    Member

    You could serialize the data using the serialize function from php.

    http://php.net/serialize

    the phpjs organization has ported the function to javascript so you could serialize it with javascript and unserialize it with PHP.


    Another solution would be to loop through each item, and join them together, and then explode them with php into separate arrays.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.