To Ajax or not to Ajax?

greg's picture

He has: 1,581 posts

Joined: Nov 2005

so, what's this ajax all about?

having searched the net, as usual, I come across some reviews saying 100% efficient, no problems or issues..
then some saying to avoid it like the plague, some saying it's ok but has plenty of faults

what is it with ajax? seems to me the ability to change page content upon the user's input WITHOUT a page reload of any kind is a remarkable tool that needs to be utilised

every site I have done or thought about would have used this ability in many pages and content

those small login forms (username/password only) that get tucked away neatly to the side , user logs in and only that login form is changed to display "Welcome back greg"
rather than having to load another page upon submit, or PHP_SELF that page to recheck your ISSET code to determine they are logged in

interactive tables, not much use in many sites, but a lot of sites have use accounts with data stored in their DB, so content changing on a page without a reload must be an amazing advantage

I read javascript itself can do it, without the amalgamation of XML
but I stray away from javascript due to users not having it enabled
people tel me it's not an issue and only a small percentage of users have JS disabled...but my thought is even 2% of internet users is tens of millions of people

but ajax is apparently good (for some reason) in saving bandwidth and only reloads in the users browser the items it needs to
doesnt javascript do that already?

what is the point of it?

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

AJAX is something of a buzzword. It's used to refer to a lot of things by different people. Technically it's just Javascript and the XMLHttpRequest object. The latter allows client-side scripts to send requests back to the server and receive responses without reloading the page. In combination with the contemporary form of "dynamic HTML" scripting, you can emulate stateful applications while hiding the HTTP transactions from the user. Add some simulated or spruced-up widgets and you get a traditional graphical user interface in appearance and behaviour, on a web page.

Advantages:

The interface can be more responsive and less intrusive. With some thought, you could enhance the usability of the site or application in all sorts of ways that were once wishful thinking, as you alluded to.

You could deliver richer, more sophisticated software live over the internet. This has beneficial implications for managing development and deployment of software -- this is the technology driving the "Web 2.0" and software-as-a-service trends. The delivery platform sometimes can be guaranteed to be available among your target audience.

Disadvantages:

Perhaps most importantly, it breaks the usage model of the web as we know it. HTTP has the advantage that you can address any page via a URI. If I load a certain thread on TWF, like this one, and decide I want to point a friend to it, I can grab the URI in my browser's address bar. But in an AJAXified site, where loading pages can be done without resetting the current location, there's no way of addressing any given page -- my friend would have to load the homepage and search for the thread independently.

Because of its reliance on the client-side, all of the classic Javascript-based problems remain. Scripting can be disabled, or not supported in the browser (particularly XMLHttpRequest, as it's not standard). Where it's partially or entirely unavailable, the site must degrade gracefully, and that's tricky to do. In current usage, AJAX sites rely heavily on graphical interfaces, which can really hamper accessibility for a general audience.

Writing rich interfaces is also difficult because AJAX doesn't come with a standard or mature toolkit. Every aspect of a toolkit's appearance and behaviour must be implemented basically from scratch, somewhere along the line. There are many libraries available for reuse but they're possibly still too immature for a lot of purposes, as they can be buggy, not widely supported, or not well-documented. They are somewhat bulky to push over the internet too, which could negate any other performance advantages AJAX gives you.

So there is a point to AJAX. But it's not always appropriate, and often can be unjustifiably complicated to implement. My opinion at this time is that AJAX should be avoided by default, and only used in circumstances where truly necessary, and the final product is guaranteed to be usable and accessible by your target audience.

Smiling

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

I used it for this fee calculator here:

http://www.housing.uwaterloo.ca/fees/calculator.php

Very simple, and it was easy to develop. It does use the xajax library, which I'm still not sure about. For something this basic I didn't feel it was a problem.

One problem I'm starting to see is people doing stupid stuff with ajax just because they can. It's just like all the other "cool" tools that have come up in the past (flash, dHTML) - just because you can do something it doesn't mean you should. I feel that ajax can sometimes enhance the user experience but you have to use it wisely.

greg's picture

He has: 1,581 posts

Joined: Nov 2005

thanks for the replies

Knowing people on here from reading their posts I know I can trust their comments, not everyone of course, but at least I have an idea of whos opinion and facts I can trust
where with google results everything I read is on face value

Megan, nice calculator.That is the kind of thing I could benefit from using (the functionality, not the calc Laughing out loud)
and I understand and agree with Abhishek's comments about not being able to give links to people, but of course if done correctly, and in the right curcumstance with the right content, the first page can be linked/bookmarked and SE listed

just like your calculator, the page with it on is easily linked to and of course the results of using it are user specific anyway
but can't what you did be done with pure Javascript? and is really what I'm asking of Ajax...why did you use that rather than just JS?

So with the potential problems (users having JS disabled aside) I suppose if used sparingly it can be useful

I suspect this will be integrated within a web standards as time goes on

cheers

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

greg;223431 wrote: but can't what you did be done with pure Javascript? and is really what I'm asking of Ajax...why did you use that rather than just JS?

It was maily because this way I could store the information in a database and potentially use it elsewhere. Like the table that is linked to from the intro - it's a static HTML page right now but I'd like to pull that from the database too. That way, when the fees change I only have to update them in one place. I suppose maybe I could have pulled all the data in using PHP and then used Javascript to manipulate it...

I also thought it would be fun to experiment with Ajax a bit Smiling

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

greg;223431 wrote: and I understand and agree with Abhishek's comments about not being able to give links to people, but of course if done correctly, and in the right curcumstance with the right content, the first page can be linked/bookmarked and SE listed

just like your calculator, the page with it on is easily linked to and of course the results of using it are user specific anyway

You still can't address specific subpages if they can only be loaded by clicking on special AJAXified links to them. If it takes three clicks to get to a page, and you have to know exactly which links out of many to click, it would be very inconvenient to point someone else to it.

That's really quite important, because it means other sites can't link directly to your content. It's an example of those stupid things people do with AJAX that Megan referred to.

You're right about her calculator. That's a good example of reasonable use of AJAX.

Smiling

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I have only used AJAX to create a button on a form that tells the user if their requested username is already being used. A lot of websites are doing it now, and I think it is a nice thing to have (better than submitting the form, and then finding out the username you want is taken).

Quote: You still can't address specific subpages if they can only be loaded by clicking on special AJAXified links to them. If it takes three clicks to get to a page, and you have to know exactly which links out of many to click, it would be very inconvenient to point someone else to it.

You could create a "Link to this page" like what Google has on Google maps. But that doesn't solve the search engine friendly problem. Laughing out loud

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

teammatt3;223453 wrote: You could create a "Link to this page" like what Google has on Google maps. But that doesn't solve the search engine friendly problem. Laughing out loud

That's a good point. But when you're used to finding state in the current query string, looking for it in a non-standard place can still be inconvenient. However, when it's appropriate, having some accessible link like that is important. And it's possible that we'll eventually standardise a neat way to point to the current page in an AJAX world, who knows.

Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.