There’s talk of not using Ajax because of the accessibility concerns. I think that’s totally valid, if you’re going to rely on Ajax alone. But that’s not really the best or right way to do things.
Thinking about Ajax, and reading others’ posts on the matter, there’s a school of thought that adheres to “Progressive Enhancement” with unobtrusive scripting. I think they’re right:
- build your application in the standard ways first
- then, overlay Ajax with unobtrusive scripting, your Ajax “Hijax” the functionality
- return a subset of what you normally would in your standard transaction
I can’t claim responsibility for the term “Hijax”, that credit without a doubt goes to Jeremy Keith.
Build a standard application
Consider a real, standard form application. And it’s interesting to note that a standard form submission really isn’t always the best place for Ajax (always ask yourself “why am I going to use Ajax?”).
User enters data, then submits. The screen refreshes and a response is generated on the server, but the response contains the whole regeneration of the page, including navigation, any calculated data or whatever processing etc.
Overlay your Ajax with Unobtrusive Scripting
Using modern scripting and DOM methods, you can interrupt the form submission onSubmit event or grab the submit button onClick handlers, and then “return false” on the form submission while sending the data up in the background using Ajax.
Finally, you’re going to want to send some data up that indicates it’s an Ajax submission as opposed to a regular submission, so potentially you can use the same server-side module to process the post, albeit in a slightly different manner.
Return a Subset of the Page
Now, your server-side app, having recognized the transaction as an Ajax transaction as opposed to a standard submission, will process the data and return just the data necessary to update the portion of the screen you’re wanting to update.
Now, you’re not worried about additional overhead of regenerating the page and the server has much less to do.
Benefits of Ajax-Hijax on Accessibility
You’ve got yourself a standard application which does the normal, accessible things. Then, when a client that supports it comes along, you’re overriding, or hijacking, the form with Ajax. Ajax becomes a means to enhance, or make better the user’s experience.
The server-side code you’ve normally used can be simply tweaked to support returning a subset of data. I’ve used this to great success several times. You’ll love it.
For further reading, please see some of Jeremy Keith’s references on the subject:
Possibly Related Articles
commenting closed for this article