0

How to post array of values in jquery-ajax?

<input type='text' name='mynameinputs[]'>
<textarea id='mydescription' name='mydescriptioninputs[]'></textarea>
<input type='text' name='myquantityinputs[]'>

<input type='text' name='mynameinputs[]'>
<textarea id='mydescription' name='mydescriptioninputs[]'></textarea>
<input type='text' name='myquantityinputs[]'>

<input type='text' name='mynameinputs[]'>
<textarea id='mydescription' name='mydescriptioninputs[]'></textarea>
<input type='text' name='myquantityinputs[]'>

$.post(url,{''}, function(data){}

How to get the values of each and post it to a php file?

1 Answer 1

5

You could use the .serialize() method on the containing form:

$.ajax({
    url: 'foo.php',
    type: 'POST',
    data: $('#if_of_the_form').serialize(),
    success: function(result) {

    }
});

$('#if_of_the_form').serialize() will format the values as if it was a normal form submit - using application/x-www-form-urlencoded.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks @Darin for the quick answer. How to catch those values though in foo.php?
The same way you would have caught them if you wasn't using any javascript at all but a standard form submission. I am not a PHP guy so cannot tell you, but I guess you will have to use $_POST or something.
Yepp, $_POST['element_name']; +1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.