iSnare.com - Free Content Articles Directory
Authors Contents [Advanced Search][Add OpenSearch][Job Search]
Distribute your articles to thousands of article sites for only $2 and below! Read more...

Index  Computers and Technology
 

How To Create Web2.0 Applications Using AJAX And Clientside HTTP Requests

 
[ Contact the Author] [ Send to a Friend] [ Article Publisher] [Make PDF] [ Print] [ Bookmark & Share]
 
Read our Terms of Service before reprinting this article. The submitter specified above has claimed the rights to this article.
Lucas Green

Web2.0 is a term coined to refer to web applications that run without visible page refreshes. A normal website functions by delivering pages of information, with links that allow a user to move from page to page. A web 2.0 application, or AJAX application, runs on a single web page, and uses clientside javascript to initiate and process additional requests to the server. The additional requests run in the background and are invisible to the user; the end result is that the web application appears very similar to a normal computer program, and the user can continue to manipulate the application and application interface without having to wait for the additional requests sent to the server to complete.

AJAX is an acronym that stands for Asynchronous Javascript and XML. The interesting thing about AJAX is that the XML component is actually unnecessary, or rather optional. The important component is asynchronous javascript -- this is the meat of how web2.0 applications work and the XML component is just one possible format for sending and receiving the additional data requests to the server. However, since this processing happens in the background and is invisible to the end user, you can actually build a web2.0 application using any format for the data requests that you wish.

The key to implementing an AJAX web2.0 application is in the XMLHTTP Object. The XMLHTTP objects exists in many forms, both server-side and client-side, and the purpose of it is to allow retrieval and processing of external web pages from within the coding application. Since we are trying to build a client-side web2.0 application, and since Javascript is the most widely available scripting application for web browsers, AJAX is the ideal implementation, and a good cross-browser Javascript code for instantiating the XMLHTTP Object is as follows:

if (document.all) req=new ActiveXObject("Microsoft.XMLHTTP");
else req=new XMLHttpRequest();

When creating a web2.0 application, the idea is that whenever you would normally send data to the server and receive a response in return by submitting a form, or using a link to an external page, instead you implement it by using the XMLHTTP object to send the request or form in the background, and process the resulting data without causing the browser to reload. The XMLHTTP Object allows you to send requests synchronously or asynchronously, but since we are creating an AJAX application you will use asynchronous mode in almost all cases. When submitting form data, you can use either the GET or POST method, but in this article I will show you how to use POST with the XMLHTTP Object as that allows you the widest possible uses.

Once you instantiate the XMLHTTP object, there are four simple commands to creating a web2.0 application. The "onreadystatechange" property is used for asynchronous mode to define a function that is executed whenever the state of the request changes (such as when it completes). The "open" method creates the request and the "send" method send the request. Also, the "setRequestHeader" method is used to specify the format of the data that is being submitted. Here is some example code that shows how a basic AJAX application would work:

if (document.all) req=new ActiveXObject("Microsoft.XMLHTTP");
else req=new XMLHttpRequest();
req.onreadystatechange=ajaxProcess;
req.open('POST','http://'+location.host+'/ajax.asp',true);
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.send('p1='+escape(p1)+'&p2='+escape(p2));

In this example, "/ajax.asp" is the page that is being retrieved, and "ajaxProcess()" is the function that is executed once the page is retrieved. The variables "p1" and "p2" are sent to the page as form data. You can of course send whatever data you wish according to what you need to do; just make sure that the ajax.asp file processes them correctly and returns the results. Define the ajaxProcess() function so that it processes the returned results, and updates the user interface to indicate that the request has been completed and updates the appropriate variables and/or the user with the new data. If you would like to see an AJAX web2.0 application in action, you can check out the web2.0 RPG I created, Apocalypse, found at www.apocrpg.com .

Using these methods, you can in fact send whatever data you want to the server and process the results, just as if you had used a normal HTTP request. The difference is that when done normally, the end user has to wait for each page to be loaded, which can be unacceptable if the user is on dialup and there are a large number of actions to be performed independently (multiple page reloads). By using AJAX in a web2.0 application, you can execute these actions in the background, and the user never notices the delays as he is able to continue manipulating your user interface while the page requests are processing in the background, invisible.

This type of web application wasn't possible in the past, for two reasons. Primarily, the XMLHTTP object wasn't available until recently, and also Javascript was not widely supported by almost all browsers as it is today. Now that background page requests are possible, it is likely that in the future all web applications will be converted or migrated to web2.0 / clientside AJAX applications. There are also innumerable web applications that simply weren't possible or feasible under the old model, that we will undoubtedly be see appearing in the next few years, that could potentially be very successful. Your website could be one of these, so get started!

Important NoticeDISCLAIMER: All information, content, and data in this article are sole opinions and/or findings of the individual user or organization that registered and submitted this article at Isnare.com without any fee. The article is strictly for educational or entertainment purposes only and should not be used in any way, implemented or applied without consultation from a professional. We at Isnare.com do not, in anyway, contribute or include our own findings, facts and opinions in any articles presented in this site. Publishing this article does not constitute Isnare.com's support or sponsorship for this article. Isnare.com is an article publishing service. Please read our Terms of Service for more information.

This article was written by Lucas Green, a professional private web developer who lives off his internet income. To visit his website and learn more about how he is creating multiple streams of passive income using the internet, please visit http://www.lucasgreen.com !
Article Tags: application [See Dictionary], page [See Dictionary], web20 [See Dictionary]
Got a question about this article? Ask the community!
Article published on January 25, 2008 at Isnare.com
 
Rate this article:

How To Install A MySQL Database Using A MySQL Injection Script
Submitted by: Lucas Green

Whenever you purchase or acquire a MySQL database (such as from a website like WebContentsorg), chances are it will come as a MySQL injection script...

Converting A MySQL Injection Script For Use In Microsoft SQL Server
Submitted by: Lucas Green

MySQL Server is the most widely used database management system in the world, primarily because it is open source and free...

How to Prevent the Noise on Your Car Stereo
Submitted by: Jack Wylde

If you do not know or cannot comprehend what that term means “noise” from your car audio system then you perhaps don’t own a car audio system yet...

Relationship With an it Solution Provider?
Submitted by: Lawrence J. Reaves

IT budgets are tight, in fact SMB’s are only reporting a 56% increase in budgets (before inflation) for the next 4 years (2009 to 2013)...

GBC CombBind C55 Review
Submitted by: Jeff McRitchie

GBC is one of the leading manufacturers of plastic comb binding machines They make both entry-level and advanced machines with units available in every imaginable price bracket...

Reviewing the GBC Comb Bind C95e Electric Comb Binding System
Submitted by: Jeff McRitchie

If you need an electric comb binding machine for your small office, the GBC CombBind C95e is definitely a machine you may want to consider...

Reviewing the GBC Comb Bind C340 Comb Binding Machine
Submitted by: Jeff McRitchie

The GBC CombBind C340 plastic comb binding machine is a relatively new product from the company, which still has the market cornered when it comes to binding machines...

GBC HeatSeal H100 Laminator Review
Submitted by: Jeff McRitchie

As a reasonably priced small pouch laminator, the HeatSeal H100 is designed for use in home offices or small businesses that occasionally need to laminate small items such as ID cards...

GBC HeatSeal H110 Laminator Review
Submitted by: Jeff McRitchie

If you're looking for a new laminator and you frequently laminate a lot of small items such as business cards, photographs, and bookmarks, you're reading the right review...

GBC HeatSeal H210 Laminator Review
Submitted by: Jeff McRitchie

The GBC HeatSeal H210 is one of the manufacturer's entry-level pouch laminating machines, intended for use by small and/or home offices...

A Review of the GBC HeatSeal H212 Laminator
Submitted by: Jeff McRitchie

Do you need an affordable, easy-to-use laminator for home or office use If so, you're reading the right review because the GBC HeatSeal H212 laminator could be just what you need...

Ways a Camera Phone Can Help in an Emergency
Submitted by: Seomul Evans

In an emergency you will require to allow and welcome help, and later it is over, you will have to return, repair, and rebuild...

Facts About Cell Phones Health Risks?
Submitted by: Seomul Evans

Through the long time, there have been so many rumors concerning the wellness risks of cell phones But we are a society that would almost rather die, than give them up...

How to Pick a Car Cassette Player
Submitted by: Jack Wylde

Cassette player for your car audio system is the most basic kind of stereo system that you can purchase for your car...

How Your Web Hosting Can Help Grow Your Business
Submitted by: Frank Hendrickson

One of the most popular ways of marketing and promotion in this time and age is through online or what everybody calls as internet marketing, web marketing or e Marketing...

Web Conferencing: Fast, Easy and Reliable Way of Connecting to People
Submitted by: Allison Clarke

Are you cringing by the thought of planning a conference Making travel arrangements, organizing numerous agendas, trying to secure a location, and the expenses will surely make anyone dismayed in setting up a conference...

Best Mini Netbooks - Mini Laptop Reviews - Samsung - Lenovo - Acer
Submitted by: James J Clarkson

Netbooks are very quickly gaining in popularity It was not all that long ago that you could go to a computer store and see only one or two brands of netbooks...

Isnare.com Footer Divider

© 2004-2009. Isnare Free Articles - An Isnare Online Technologies Free Articles Project. All Rights Reserved.   Privacy Policy