Web pages with AJAX tricks load extra content when certain parts of the page are clicked without reloading the entire page. This improves the visitor's experience. Wouldn't you like to get that functionality for your web site? This four-part series shows you how to do it with a technique called "click interception."
Using Click Interceptions with JavaScript - Full source code for the click interceptions demonstration (Page 4 of 4 )
As I stated in the previous section, below I included the complete definition of the two source files that comprise this basic example of using click interceptions with JavaScript. As you know, in this specific case, this client-side approach is utilized to submit a basic web form with Ajax, but naturally, it can be applied within the context of other web applications as well.
Having said that, here's how the mentioned source files look:
(definition of 'sample_form.htm' file)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Definitely, the pair of source files listed above are a good example of developing a click interception mechanism with JavaScript for submitting a simple web form via AJAX. In addition, you must realize that even when scripting is disabled on the browser for whatever reasons, the web form will still work correctly. This implies that the JavaScript application is also capable of offering a graceful degradation in this situation. What else can you ask for?
Final thoughts
In this initial chapter of the series, I explained the basic concepts that surround the implementation of click interceptions with JavaScript, and included an example to illustrate my points. As you saw earlier, this approach can be quite useful when it comes to extending the existing behavior of different web applications in an unobtrusive way.
In the upcoming part of the series, I'm going to show you how to use click interceptions to build an expansible image gallery. Now that you've been warned, you don't have any excuses to miss it!
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.