Home arrow JavaScript arrow A Basic Approach to Server-side Data Validation with AJAX

A Basic Approach to Server-side Data Validation with AJAX

Would you like to learn how to validate user-supplied data using JavaScript, but without the risks? This article will show you how to handle it in a way that takes advantage of JavaScript's pluses, but adds a level of safety, thanks to AJAX. It is the first of three parts.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 17
July 11, 2006
  1. · A Basic Approach to Server-side Data Validation with AJAX
  2. · A picture is worth a thousand words: defining the look and feel of the application
  3. · Building a basic sample form: defining the front-end of the AJAX-based form checking system
  4. · Spicing up the sample form: defining a few CSS declarations
  5. · Putting the pieces together: listing the full (X)HTML markup and CSS styles of the AJAX application

print this article

A Basic Approach to Server-side Data Validation with AJAX
(Page 1 of 5 )

A downloadable file for this article is available here.

Validating user-supplied data has been for years a highly discussed topic within the huge area of Web development. What really makes this subject an interesting thing is its significant grade of evolution during the last few years, being specifically empowered by the capacities of the different server-side scripting languages.

While validating online forms with JavaScript is a feature that can still be found on numerous websites, the truth is that this approach delivers extremely unsafe and unreliable results, particularly if the data being submitted affects some sensitive areas of those sites. Of course what I just said isn't breaking news to you, and quite probably you've been using your own server-side validation routines for a long time; as a result, JavaScript doesn't fit into your scheme any longer.

Nevertheless, one of the most appreciated advantages of using JavaScript-based validation rests mainly on its quick response, which makes it very suitable for notifying the user as to what data is wrong, as soon as he/she has finished typing a value on a specific form field. Unfortunately, as with everything in life, this responsiveness comes at a cost, and the drawback of this approach consists of its complete dependency on using scripting-enabled browsers, in order to perform the validation on the data in question.

But it's not all bad news when it comes to using JavaScript for checking user input. With the help of AJAX and a handy group of server-side validation routines, it's possible to have a relatively fast system, which can inform the user via JavaScript when invalid data was entered on an online form, while the real validation is performed on the server, with the scripting language of your choice.

Aside from the advantages that I mentioned before, this validation mechanism can be developed bearing in mind specific conditions where JavaScript has been disabled by the client, while still maintaining its full validation capabilities on the server. Indeed, this approach can be quite useful for constructing richer Web applications, and that's precisely what I'm going to do in the next few lines: build an AJAX-driven form validation application, which will use PHP for validating data on the server.

Of course, due to the versatility of the application that I plan to build, you can use your favorite server-side scripting language instead of PHP, and keep the same functionality. Okay, I'll stop wasting your precious time and go straight to showing you how to create this little AJAX-based application. Let's get going!

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials