How do you avoid duplication of validation on the

2019-03-25 10:11发布

How do you avoid duplication of validation on the server and client-side? Is there a web programming platform that generates one from the other, so I don't have to keep the two in sync?

8条回答
Luminary・发光体
2楼-- · 2019-03-25 11:12

Most forsake client side scripting and just do server side nowadays. You can use ajax when sending the post, so that the response is a bit lighter weight than reloading the whole page.

查看更多
等我变得足够好
3楼-- · 2019-03-25 11:13

Server-side validation is required simply because client-side validation can be disabled.

Client-side validation isn't required, but it makes your application more responsive during error handling, as you no longer need to do a form submit to the server and wait for the resulting page to come back.

A well-designed application uses both.

As a side note, Ajax can be used for certain kinds of validation, such as checking for duplicate usernames on a user registration form. However, basic validation, such as checking if a field contains only numbers, should be done without it.

查看更多
登录 后发表回答