Why Hijax (or Ajax) on Forms is No Good
On a recent team project that had an accessibility / usability requirement my influence (almost insanely) tipped us from accessible to inaccessible on the contact form. My motivation was wanting to experiment with Jeremy Keith’s Hijax so there’s nobody to blame but me.
Initially we did all of our crucial form validation in a Hypertext Preprocessor (PHP) script and enhanced the form unobtrusively with a second JavaScript file that did very basic empty field and email format checks. If the user had JavaScript enabled that’s great but if they didn’t then they simply got the same experience from PHP, only it was slower due to the page refresh.
That’s good. That’s how it needs to be. The idea is to save tying up the server unnecessarily with requests and responses that can be avoided on the client.
But then I thought that I really wanted to experiment with Hijax regardless of the theory. Ajax just looks and sounds cool, right? Who’s with me there. So basically we used Jeremy’s Hijax script to hijack the request / response and the PHP script did all the work. It looks very swish and cool when you’re explaining it all to someone for the first time.
Here’s why its a bad thing. Yes I knew this theory in advance, too. First the user (me included) is going to hit that Back Button to go to the last state - which takes them to the last page visited. It breaks user expectation and I seemed a major culprit at hitting the Back Button even as a developer. That should be a sign. The second big reason was that this was inaccessible (or at least unusable to some of the audience with disabilities) because screen readers don’t get notified there was an update to the page. So although a fancy notification was entered into the label that something was invalid, users of assistive technologies just don’t know of the update and could be waiting for this form to process. Which it won’t, of course. It’s again waiting for valid input.
What I have come to realise is that if we are going to play with Ajax at all on projects it should never be anything as critical as a contact form. When we know a better way versus a cooler and trendier way we need to be bold enough to follow the best technical path towards the goal. I just thought I’d mention that, preaching to the converted, because we all make bad decisions sometimes in our work. None of us are perfect. Especially under pressure and with deadlines.






