5

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.

0

2 Answers 2

7

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');
});
Sign up to request clarification or add additional context in comments.

Comments

1

You'll want to use jQuery's .serialize() method.
Check it out

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.