I have several dynamically created hidden input fields. Most of which have a name formatted as array[]
Question 1:
How can I use jQuery .ajax()
or .post()
to get the values from every field named array[]
and pass them so they'll be retrievable as $_POST['array']
in my PHP page?
Question 2:
Hypothetically speaking. Let's say that I don't know the name of said field but only the name of the form. How can I still do the same thing as in Question 1?
I found .serializeArray()
in the jQuery documentation, but I have no idea what I'm doing with that and I'm not even certain if that applies to my situation of not knowing the field names.
Thanks in advance.
You want to use .serialize()
on the form. This will make a query string of all form elements (including 'name[]' ones).
$.post('/url/to/post', $('#form').serialize(), function(data){
alert('POSTed');
});
You'll want to use jQuery's .serialize()
method.
Check it out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With