最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Should I avoid using javascript and jquery in my website? - Stack Overflow

programmeradmin3浏览0评论

I use some jquery and JS functions to validate forms and to check for example if that field is empty or password is less than 6 characters, and stuff like that, and I noticed that if someone disabled JS, then these functions would be useless, and no more protection of forms, which can be better made using PHP, so should I avoid them now because this could cause an insult to my website ?

I use some jquery and JS functions to validate forms and to check for example if that field is empty or password is less than 6 characters, and stuff like that, and I noticed that if someone disabled JS, then these functions would be useless, and no more protection of forms, which can be better made using PHP, so should I avoid them now because this could cause an insult to my website ?

Share Improve this question asked May 3, 2012 at 9:11 Ali BassamAli Bassam 9,96924 gold badges70 silver badges119 bronze badges 2
  • possible duplicate of JavaScript: client-side vs. server-side validation – Felix Kling Commented May 3, 2012 at 9:16
  • JS validating of forms on client-side isn't sufficient. You should also check the value sent by the client to the server on server-side. For this is the appropriate php for example. – kapandron Commented May 21, 2012 at 19:51
Add a ment  | 

7 Answers 7

Reset to default 8

JavaScript is very useful for improving user-interaction, along with reducing the number of requests made on the server; but, as you've pointed out, it can be disabled. To answer your question: No, I wouldn't remend avoiding the use of JavaScript, but the key is not to rely on it for critical actions, such as validation. You'll want to implement the validation on both the client (JavaScript) and server (PHP) sides. This will ensure that there is no way for the user to pletely disable the validation.

In short:

  • JavaScript = Good
  • JavaScript Validation = Nice for the user, but not reliable
  • Server Side Validation = Essential

Side note:

With regards to relying on JavaScript for the overall user interaction, as other answers have suggested, use JavaScript to enhance the overall experience, but don't rely on the user having it turned on. I would remend a bit of bed time reading of Progressive Enhancement, it's the approach of making something better, with being reliant on it, and can be applied to more than just JavaScript (CSS3 etc).

You should use javascript and jQuery to enhance the functionality of your site. If someone has javascript turned off you should ensure that the site still works, and they can access all areas - even though there may be some things they cannot see, such as transitions and effects.

With regard to validation, you should ALWAYS validate server side. Client side validation is optional, but a very nice feature to improve the user experience for your visitors.

I don't mean this as a plaint, more of an observation.

Web developers often grab Javascript libraries as the latest shiny toys with no thought for the consequences. As a Data Governance person, I'm regularly the bringer of bad news, when we do audits on the data collected, and find users who get past the Javascript validation.

"Go back and start again".

Javascript libraries are great for the presentation of data, but should and must not be relied on for data validation and the integrity of user profiles.

A validation should always happen at

  • Client Side - using javascript to enhance the user experience.
  • Server Side - using the preferred server side programming language for security reasons
  • Service Side - if you are following SOA / Web API as part of defensive programming practice. This can also be at the DB level along with Service layer.

You should not avoid using JS and jQuery in your website, but you should avoid using them for validation purposes or business-logic purposes. These should be done in the back-end of the website, not in the UI level.

You shouldn't really avoid them. What you should do is to implement both client and server validation. Don't rely just on client validation, for the reasons you just mentioned. You should always validate the data when it arrives to server.

Adding client-side validation gives your pages dynamic look and feel. A user does not have to wait for the form to go to server and in case of an error to return back. It is automatically verified without postback.

As I said above, don't rely upon client side validation. Always implement server-side validation also.

Remember my friend, Java script is client side scripting. its purpose to validate form at client side itself so we can avoid overhead...You must use java script at client side. because PHp is server side language. It will take time to reply.

Ha, Server Side validations are equally important. if you want to do that, then you can use server side language. You can check ment below to my post by halfer. Server side validations are important for security and many more purposes.

That is different thing that somebody disabled js. You can check for the same and give proper message to enable.

发布评论

评论列表(0)

  1. 暂无评论