JavaScript Remote Scripting: Building an AJAX-based Random Code Generator
(Page 1 of 4 )
This article explains how to build a random code generator, specifically applied to a voting system. This will help you to avoid system hacks involving automated submissions.
This is part four of the series “JavaScript Remote Scripting.” Welcome back. As you probably remember, over the previous tutorial I explained how to use standard DOM methods for fetching server-side parsed XML files and displaying their contents on a browser. Since most remote scripting concepts are best understood by example, I followed a practical approximation by exploring the makings of a JavaScript-based application aimed at displaying some headlines, which were originally structured as XML nodes within a data file.
Whether you’re wishing to go through the implementation of simple JavaScript snippets for sending silent http requests on the fly and provide visitors with richer interactivity, or building a full-featured application that relies heavily on XML for running a Web service, remote scripting based on JavaScript can bring you additional functionality without the need to mess up programming logic with “dirty” code for handling overlapped application layers.
Now, by taking another look at the series of practical examples that I showed in my previous articles, in this part of the tutorial, I’ll go through the required explanations –- of course, accompanied by the appropriate source code -- for developing a random code generator, specifically applied to a voting system, similar to many applications that you can find on the Web today. Certainly, for the sake of clarity, let me explain first what you’ll find out in this article: I’m not going to demonstrate how to build a full-blown voting system, since that’s out of the scope of this tutorial. Instead, I’ll show you how to add some boxes populated with challenge values (generated on the server). This will avoid leaving the system, which requires a user to enter data manually, vulnerable to being hacked with automated submissions.
The main advantage of implementing such as protecting mechanism is that you can develop your voting system (or another application) by coding all the required data validation on the server, while maintaining the extra functionality offered by JavaScript only on browsers with scripting enabled. By writing the application from that programming point of view, you can make sure that the security of the program, as well as its overall operability, is never compromised by the availability (or not) of JavaScript in the client.
Having detailed the key concepts for applying remote scripting on a random data generator, it’s time to move on and start coding the application. Let’s go!
Next: Protecting against automated data submission: the basics of a random data generator >>
More JavaScript Articles
More By Alejandro Gervasio