SiberianGuy
SiberianGuy

Reputation: 25312

To ajax or not to ajax form validation?

I see two common ways to implement form validation:

  1. Send form by ajax, retrieve success flag and in the case of success redirect somewhere
  2. Classical Post-Redirect-Get

What is the prefered way?

According to my observation, redirect is slower in the case of Ajax approach as instead of simple redirect we have to parse form validation result sign and change location by JavaScript.

On the contrary Ajax approach is quicker for failed validation cases as you get instant feedback without page reloading (you can achieve it with classical approach if you client validation absolutely repeats server validation).

Your points?

Upvotes: 0

Views: 196

Answers (1)

Nexerus
Nexerus

Reputation: 1088

I'm not sure about what others do, but I usually do something like using javascript and ajax where needed for validating as the user fills in the form, then after they submit the form, assuming the javascript/ajax validation is successful, do another quick validation before doing anything with the database, if there are validation errors, show the form again with a list of errors.

Upvotes: 1

Related Questions