AJAX has spread far and wide, moving into territory it was never meant for, harming accessibility, even though this can often be avoided with little more than a fallback page for those user agents that don't support it.
The back button has meaning
Using AJAX to replace large portions of content on a page is very bad practice, as it breaks various basic browser features, such as the back/forward buttons and bookmarking. While there are Javascript hacks to get the back button working in some browsers, they are still no more than hacks; furthermore, these hacks don't get the forward button or bookmarking working at all in any browser.
Multi-page forms
Many sites have forms that span multiple pages, and use AJAX to send off data, and get appropriate data for the next page. There are two problems with this practice:
- If you want to return to the previous page and want to edit what you entered, you cannot do so without redoing all the previous pages.
- If the user agent doesn't support AJAX, and there is no fallback page, then the form become unusable.
The first problem has a simple solution: have a back button; whereas the second requires a fallback page, preferably that looks identical to the AJAX form, just with each page being sent off to the server separately.
A lot of the above is also true for forms with just a single page: if you rely on AJAX to submit a form, it quite simply won't work in browsers which don't support it.
So, where can you use AJAX?
To add extra functionality that improves the user experience on the site, and where nothing is lost by it not being there, or, to submit small changes to data, with (fully functional) fallback for browsers without support for AJAX, where the fallback looks identical.
Some examples:
- Updating content in a page, such as on a shoutbox
- A delete button, to remove a list item or other small piece of content, with a fallback for browsers without support for AJAX (such as the same page, with a query string on the URL, such as delete=20)
Wow, is there that little to it?
Yeah. Most of it just boils down to using AJAX only where appropriate, and not using it everywhere you can. While this may seem insanely simple, there are many major sites that abuse these simple accessibility rules. It should take nothing more than a few minutes just to think, is AJAX really sensible here? Is anything lost to those who can't use it, or do I need a provide fallback for those who can't?