A Look At AJAX: Outside Help

Well, with the crashing of my computer, I appear to have lost the AJAX examples I had been working on in my spare time (which has been rather scarce lately), so I'm going to wrap up the series by giving some references of places to look for more information. I found these sites useful when trying to learn AJAX, and I'm sure you will too!

Hopefully you'll find enough there to get you started. And if you ever get some AJAX working and come up with a really cool feature for your church website, feel free to let me know so we can share it with the world!

Good luck and happy coding!

A Look At Ajax: Split Identity

While looking into Ajax in my spare time (which, admittedly, I haven't had too much of lately), I found out that this is another case where Internet Explorer and the rest of the browser world.  The basis of the functionality of AJAX is the XMLHttpRequest object, which is built in JavaScript.  However, IE builds this object differently from most other browsers by using ActiveXObjects to do so:

<script>
var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (error) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (error2) {
    xmlHttp = false;
  }
}
</script>

Now, you may be wondering why there are two different types of calls to create our XMLHttpRequest object.  The reason is that Microsoft's browsers support both XML, an international standard, as well as MSXML, which is an extension on XML designed to help it play nicer with non-browser applications like Microsoft Office.

Now, if we reach the point in the try statement where xmlHttp is assigned to false, then we're likely dealing with a non-IE browser.  If we're working with another browser, then we're only going to create one kind of XMLHttpRequest object, which we can do in a single line:

<script>
var xmlHttp = new XMLHttpRequest object;.
</script>

With these two different standards for the groundwork of AJAX, we're going to need a way to support any AJAX-enabled browser.  Otherwise, a number of people may never have access to certain features of the site.

<script>
var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (error) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (error2) {
    xmlHttp = false;
  }
}

if (!xmlHttp && typeof(XMLHttpRequest) != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
</script>

The reason we don't immediately assume that we can use the non-Microsoft browser implementation of the XMLHttpRequest object is because there is also the chance that the browser being used does not support the use of AJAX.  In that case, we do not want to try and build the XMLHttpRequest object because the page will throw an error.

Now that we have the basic object for AJAX functionality, we will next need to put it to use.  In the next part of this series, we will look to do just that.

A Look At AJAX: Pros and Cons

After taking a look at what AJAX is last week, this week I'm taking a look at the pros and cons of using it in web design. Like any tool, it has its strenghts and weaknesses, and it's important to understand those to better utilze its functionality.

PROS

  • Update Only What You Need To On A Page - Take the poll on the right as an example. Currently, when a vote is submitted, a whole new page is loaded from the server into the browser. However, if I were to implement the poll using AJAX, I could have only the poll section of the page reload when a vote is cast.
  • Save Server Processing and Bandwitdth - If you've got a lot of pages where only a small portion of the page needs to be changed, then implementing AJAX can cut down on the number and size of calls to the server.
  • Separation of Data From Layout and Style - Using AJAX allows you to keep the data separate from layout and style by only loading the data that needs loaded and maintaining the main layout and styles already defined by the initial page.

CONS

  • Not All Users Have JavaScript Enabled - For security reasons, a percentage of users have blocked JavaScripts from running, so these users won't see AJAX functionality. This can be accounted for in your code in terms of site functionality, but you won't get the same performance benefits with these users.
  • Not All Users Have The Same Version of JavaScript Installed - So, any bleeding edge functionality my error out on some computers. This may result in the need for more testing on different versions of JavaScript available in different browsers to make sure they all work as expected.
  • AJAX Can Break Site Pageflow - AJAX functionality breaks the use of the back button in most browsers, so any segment of your page you implement it on needs to have a way to get back to if there is any need to users to do so.
  • Most Search Engines Can't Reach AJAX Content - Since search engines don't typically, enable JavaScript support most search engines won't be able to reach AJAX enabled content. In order to make sure that this content can still be indexed, the equivalent data will need to be available at a public URL.

As you can see, there are certainly some cases that make better choices for AJAX content, and some where implementing AJAX can be more trouble than it is worth. Take the time to decide how you wante to use AJAX on your site to determine if it is the best choice for your site.

Next week, we'll start taking a look at how to implement basic AJAX functionality on a site. Be sure to swing by then!

A Look At AJAX: What is it?

In the internet world of Web2.0, you've probably heard something about AJAX. After all, it would be pretty hard to not have heard of it if you're a webmaster, designer or developer. However, I've found that many people don't have a full understanding of what AJAX is, can do, and what the benefits and drawbacks are. I have to say, I'm one of these people, as I know something about it, but definately could learn some more.

Over the next few weeks, I'm going to be taking time to learn some more about AJAX myself, and sharing my journey with all of you, much like I did more succintly with CSS last year. Hopefully, you'll learn a little bit from this as I do.

Let's start with "What AJAX Is". AJAX is short for Asynchronous JavaScript and XML, meaning that it is a web development technique, not a new programming language. The use of JavaScript and XML also means that any modern web browser and web server should provide the basic support needed to implement AJAX code.

Typically, when you place a link on a page, it leads to another full page. So even if 90% of the content is the same, the whole new page needs to be sent by the server and processed by the browser. What is unique about AJAX is that it allows you to focus that link to only update a certain portion of the page. So with AJAX, if you only want to update that 10% of the page, you can, saving bandwidth.

AJAX is also nothing new, as many of it's features have been available to developers for nearly a decade now. Out of the roots of Remote Scripting, the process slowly developed until the term AJAX was coined by Jesse James Garrett in 2005.

When used right, these calls can also make a page much more interactive, with features like search-term suggestions, tooltips, or even whole sites contained in the framework of a single page. What this does is open up more atypical page design options for us web people to work with and explore, and we're just begging to see where those options will lead us in the future.

Next week, we'll take a look more closely at the benefits and drawbacks of using AJAX, so be sure to check in then.

BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Greg