0

Let's say I have a form that has multiple inputs. Like an array... so we'd have:

<input name='firstname[]' type='text' value='' /> <input name='lastname[]' type='text' value='' /> <input name='dob[]' type='text' value='' /> 
<input name='firstname[]' type='text' value='' /> <input name='lastname[]' type='text' value='' /> <input name='dob[]' type='text' value='' /> 
<input name='firstname[]' type='text' value='' /> <input name='lastname[]' type='text' value='' /> <input name='dob[]' type='text' value='' /> 
<input name='firstname[]' type='text' value='' /> <input name='lastname[]' type='text' value='' /> <input name='dob[]' type='text' value='' />

Imagine instead of 4, there is like 50. OK, so the way I do it right now is through a regular HTML form submission using PHP like so:

foreach ($_POST['firstname'] as $fname) {
...
}

Anyway, would it be better to do it through a JavaScript foreach event where each submission is submitted or do one simple AJAX request then after that one is finished.. go to the next one until the submissions is done.

2 Answers 2

4

HTTP requests are (in relative terms) very time consuming.

Send all the data in one go, just as you do with a regular form submission.

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

Comments

1

Serialize the Form elements and send as JSON to the other side.

var data = $("form").serialize()

$.ajax({ ... data:data .....

})

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.