Archive for May, 2006

May 14, 2006

Start Using Ajax Today, It’s Easy!

Amid the confusions and the hype about Ajax, it turns out that using this browser-based technology is, well, pretty easy. You do need to have a some understanding of HTML because part of using Ajax is the ability to programmatically manipulate HTML components. You also need to have some programming background because you will be writing mostly JavaScript code when developing in Ajax.

In this blog entry, my job is to convince you that Ajax is EASY and you should start using it today.

The Resurgence of JavaScript
When you ear people talk about Ajax, they are really talking about browser programming using JavaScript. Over the years, JavaScript has matured into a powerful and agile scripting language. Before the mass epiphany (see previous blog entry) of the capabilities of language, the most exercise that JavaScript received was the development of dynamic menus on web pages. With the Ajax movement, developers are realizing that JavaScript provides powerful development platform rivaling desktop technologies.

XMLHTTP Object Changed Everything
The star of the Ajax Show is the JavaScript object called “XMLHTTP”. This object facilitates the “asynchronous” functionalities of AJAX (Asynchronous JavaScript and XML) approach. Back in version 5, Microsoft (yes, Microsoft started it first) introduced the capability to seamlessly send requests to a web server without causing a screen refresh.

This simple feature is at the heart of the browser’s rich client Ajax evolution. In traditional usage model, the browser refreshes the screen automatically with each request to the server which causes the screen to loose all of its states. Using JavaScript and the XMLHTTP request object, a web page can open a connection to the server and receive data without having the browser page refresh. The page maintains its state and the programmer only updates the necessary components.

Your First Ajax Page
In deed, using Ajax is easy (if you have worked with HTML before). If you are familiar with HTML and its components you are 80% there. The rest is to become familiar with JavaScript and the browser’s built-in API’s that let you programmatically control the HTML components.

Hello AJAX World
In this example, we are going to update the content of a page without doing any page refresh to demonstrate the basic of Ajax technologies. Our example will have the followings:

  • An input text box
  • A button
  • A span tag

function sayHello() {
// query DOM set for specific elements by ID
var label = document.getElementById(“label”);
var name = document.getElementById(“name”).value;

// change element styles on the fly
if(!name) {
label.style.backgroundColor = “red”;
label.style.color = “white”;
msg = “Enter your name now or else!”;
}else{
label.style.backgroundColor = “blue”;
label.style.color = “white”;
msg = “Hello ” + name;
}

// update lement content on the fly
label.innerHTML= msg;
}

Hell AJAX World!

Enter Name:


(Copy, paste, and save in an html file. Tested with Firefox 1.x and IE 6)

This simple HTML page depicts several important aspects of Ajax technologies:

  • Ability to query the DOM set to retrieve specific HTML components using document.getElementById() method.
  • Retrieve value of components.
  • Use JavaScript to update content and style of HTML components.

The majority of your Ajax code will be spent on the activities listed above. Once you master and understand how to use JavaScript effectively to manipulate your HTML components, the rest is even easier.

As I said in the beginning of the this blog, Ajax is easy and I have demonstrated it through a simple Hello-World-style example. In my next blog we will explore more complicated examples using the XMLHTTP request object to send data back to the server.

May 9, 2006

What Is This AJAX ?

People ask me all the time about Ajax and the techlogies behind it. To start this blog entry, I want to dispel the myths about what Ajax is not and then I will explain what Ajax is.

What Ajax Is Not

  • Ajax is not new technology.
  • Ajax is not a new TCP/IP or any other types of wire protocol.
  • Ajax is not a new Java-based technology.
  • Ajax is not a Microsoft, ASP.Net, or #C technology.
  • Ajax does not need JSP, Servlet, ASP, Ruby, Python, Groovy, etc to work.
  • Ajax won’t make you build better application.
  • Ajax won’t make your code work better if it already sucks.
  • Ajax will not fix a crappy intranet nor will it make your enterprise code work better.
  • Ajax will not make you look better to the opposite sex.
  • And, no matter how hard you try, this Ajax will not clean your bathroom.

What Is Ajax?
OK, so if Ajax is none of the above, then what is this darn thing? Actually, it’s a simple answer. Well, no, not really, it’s several simple answers and here they are:

AJAX
Well it stands for Asynchronous JavaScript and XML. Turns out, when you use Ajax-based technologies, you mostly use the JavaScript part. Both the Asynchronous and the XML part are optional (see future blogs).

A Mass Epiphany
Ajax is a mass epiphany of an entire industry of the capabilities and merits of browser-side technologies and JavaScript after Google Map was released. The giant’s mapping tool demonstrates what can be accomplished with JavaScript and some creativity. Before Google Map, the Server was reigning king. Every Api, toolset, framework, etc was developed for the server(witness the proliferation of Java’s and .Net’s server-side frameworks). Most software makers thought the next big thing was going to come out of the next sever framework. However, Google shatter that vision by placing focus once again (and rightly so) on the client.

An Evolution not Revolution
The technologies applied in Ajax are at least five years old and some have been available even longer. If you are old enough to remember the the great Browser War of the late 90′s then you will recall how Microsoft and Netscape fought for browser supremacy. During that period, browser technologies took a backseat while these two duke it out. Eventually, Netscape lost and Microsoft took the helm for a period where it concentrated on its .Net server-side technologies while the client-side stagnated and developers abandoned the browser and JavaScript.

The resurgence of Netscape (in Mozilla clothing) meant that developers had, once again, the backing of a company dedicated solely to the browser. The new browser concentrated on cleanly implementing W3C’s standards and in a swallow-your-pride-if-you-can’t-beat-them-join-them strategy, Mozilla implemented the XMLHttp Request JavaScript object (the importance of which you will find in future blog entries). That object was originally implemented by Microsoft in their Internet Explorer in versions as far back as 5.0. This single addition to the browser let developers make server requests programmatically to the server and seamlessly handle the response without a page refresh.

A Collection of Technologies
Ajax denotes a set of technologies and standards including XHTML, Cascading Style Sheet (CSS), XSLT, DOM. In modern browsers including Mozilla Firefox, Apples’s Safari, Opera, Konqueror, and Internet Explorer JavaScript allows total programatic controls over these browswer-supported technologies. This means that a developer can programatically control all objects rendered on the web page. This control is reminiscent to desktop programming using tools such as Java Swing or .Net C#. However, I would argue that in JavaScript it’s simpler and easier and afford greater creativity!

Future
In this blog entry, I scratched the surface of what Ajax is and in future blogs, we will investigate

  • how to use Ajax
  • why you should consider using Ajax
  • Explore other Rich Internatet Application technologies (XUL, Laszlo, etc)
  • the relationship between browser programming and rise of SOA
  • Effective development of browser client/SOA
  • how Ajax will affect server-side technologies

Stay Tuned!

I appreciate all feedbacks.

Follow

Get every new post delivered to your Inbox.