Comments on Getting Started with Ajax

36 Reader Comments

Back to the Article
  1. While I’m sure many people will love this article and use it for the Greater Good, I do feel uncomfortable reading anything regarding AJAX (except for the soccer club) where the author doesn’t explain that it is not meant to replace websites and large web applications.

    Surely some of you visit Digg.com once every minute, and you may have noticed the overabundance of AJAX-related posts on that site. Some “cewl thingz” we’ve seen so far: An entire forum made up in AJAX and an entire weblog made up in AJAX. Cool huh? Think again: your back button doesn’t work, you have to click a text link instead. You can’t bookmark anything, no more “hey mom click this link for the latest news on IE7”.

    People need to stop writing articles on how to use AJAX, people should start writing about how to NOT use AJAX.

    Copy & paste the code below to embed this comment.
  2. Once again, I think Gmail provides the clearest example of Ajax Done Right. The back button breaks most of the time, except when it’s most critical—-going back from a message to the inbox.

    One really terrific way to learn the ways of the Ajax, in my opinion, is through working with the Google Maps API. It exposes a cross-browser Ajax object, plus it provides a cross-browser facility for crunching xslt. So even if innerHTML is fine in your book, you can do the “right thing” and transform raw data into a table node, and then attach it to your existing page. All without any hassle.

    Copy & paste the code below to embed this comment.
  3. Hageman, if I had a nickel for every article, forum post, blog post, and website that waved the specter of Ajax usability woes in front of my face, the federal mints would have to start making more nickels. Fact is, every time someone so much as *mentions* the word Ajax, you can be guaranteed at least ten warnings like yours (keep an eye on this thread, for example).

    Fact is, you’re always going to have people mucking up usability, and you’re always going to have people who care a great deal about usability. Some of the folks doing the “kewl stuff” are just hacks, but some of them are pioneers. You can’t make an omelette without breaking a few ova after all. I, for one, am happy to see an article that actually deals with a nuts and bolts problem rather than harping on usablilty once again.

    Copy & paste the code below to embed this comment.
  4. Doesn’t this break the accessibility model? Isn’t that going to be the whole problem with AJAX is that it breaks all the rules of accessibility?

    Copy & paste the code below to embed this comment.
  5. I don’t mean to pick nits, but 12345 is the zip code for Schenectady, NY, not Anytown, NY.  -)

    Copy & paste the code below to embed this comment.
  6. Libraries such as Sajax provide all the benefits of ajax without handling the low-level. Simple callbacks are doing the work for you.

    “Digg Buzz alert”:http://www.comagz.com/webmagazine/story/digg_buzz_alert_linkadelic_coolprojects_proj was done in a few hours using this lib without prior ajax knowledge.

    Copy & paste the code below to embed this comment.
  7. It was definitely a good excerpt from the book… however, I think the point has already been brought up that with the ‘craze’ that people have jumped on with Ajax, it is a safe idea to always include a way to make the code unobtrusive. The example, just by itself, entirely breaks without Javascript enabled and if someone is (as was mentioned by CoMags Founder) using a library for the scripts, they may be doing it for speed and convenience, not for accessibility. Granted, if you are making something grand-scale (ala Gmail), maybe (debateable) you can afford to require Javascript with no alternative way to get the content - but most sites don’t fit that mold.

    Copy & paste the code below to embed this comment.
  8. >has been completely rewritten to reflect the best practices of the web standards world and is on shelves now

    Not in the UK yet, unfortunately. But a great book, and I’m sure this edition will be worth getting.

    Copy & paste the code below to embed this comment.
  9. After staring at the same Valentine’s posts for seemingly an age, I was so excited to see an article on AJAX arrive. Always one to expand my knowledgebase this would be a good point to look into a new technology.

    Then within 3 lines I read “nonstandard XMLHttpRequest()” and it’s put me off. IMHO with the drive of recent years to move towards standards and accessibility, to have the very core of this wonderful (new) technology based on a nonstandard device seems to be self-defeating. And with the references to breaking accessibility and the use of innerHTML (isn’t that IE only?) I really don’t think I’m going to bother now. This is really screaming “quick let’s use every fudge we can to make it work on every browser”, which is a mentality which annoyed me in ‘97 when it was all the rage, and I really hate it now.

    I’ll keep my eyes open and come back to it in a few versions time when AJAX has matured and Microsoft stop pi**ing about and make IE work.

    Unless somebody can convince me otherwise?

    Copy & paste the code below to embed this comment.
  10. I subscribe to Dean’s view: AJAX is very often an accessibility-killer. One should use it cautious.

    Copy & paste the code below to embed this comment.
  11. @Ross Clutterbuck: You shouldn’t allow yourself to be put off by the word “nonstandard” in this context. There was a time when HTML was nonstandard, for the simple reason that the standard hadn’t been written yet. Work is currently in progress to create the standard defining the behaviour of XMLHttpRequest, and it will reflect the behaviour of the technology as it now exists. And it’s not really fair to knock Internet Explorer in this context, as it was the first browser to offer this capability. (It’s fair to knock it in every other context, though… until IE7 arrives.)

    XMLHttpRequest works across the major browsers, and the code necessary to account for IE less than 7 is a simple if….else… which is easily isolated to a function a few lines long. All existing Ajax libraries that I am aware of have already abstracted away this implementation detail for you.

    The work people are doing with Ajax bears no comparison with the way we were forced to work in 1997. Although the use of innerHTML isn’t something I personally would encourage, it is supported cross-browser, even though it’s not part of any standard. If, like me, you prefer to steer clear of it, there are plenty of places where you can learn standards-based DOM scripting techniques and use them instead. (Note that the innerHTML/DOM debate has nothing to do with Ajax.)

    I’ve been using the techniques now known as Ajax since 2000, but they were restricted to intranet projects because they were supported by IE only. The fact that the other browsers have caught up is the indication that Ajax _has_ matured. It’s time to start using it - when appropriate, and with proper fallback behaviour and accessibility options. A bunch of script kiddies making broken “cool” things just because they can is no reason for a professional to dismiss a valuable toolset in its entirety.

    Copy & paste the code below to embed this comment.
  12. I enjoyed this article. The trouble is that it felt like only half the story. What’s happening on the server? What sort of script is parsing the XML? What sort of XML? Is it raw XML or are you retrieving data from a database? I’d love a follow-up article detailing that part of the story. Unfortunately, as it is, I can’t do very much with the AJAX tips you provided. But it was a very good start.

    Copy & paste the code below to embed this comment.
  13. AJAX and accessibility - two words you seldom hear together, and when you do it’s either to dismiss it (“hey, this is a web *application*”) or it skirts around the point with a hand-waving reference to “making it work without javascript”

    But there’s more to it than that.  More complex and more subtle problems arise with devices which *do* support javascript, but which may still not be able to interact with the script. Browser-based screenreaders are among such devices, and for them, progressive enhancement doesn’t work - they are script capable browsers, but their ability to deal with JS is nothing like par with the browser used on its own. 

    Have a look at some of the information we collected at Access Matters for evidence of this - http://www.access-matters.com/index/index-of-javascript-tests/

    What we need more of (and I have something in the pipeline to this effect) is articles that stress:

    1 - AJAX is not a suitable replacement for traditional POST/response functionality. It should not be used as such, but only for situations where there is no other way to acheive the same functionality.

    2 - AJAX applications, as far as has been established so far, cannot be made accessible to screenreaders, and so - *any* AJAX application must make a noscript alternative available *as an explicit advance option* - not relying on progressive enhancement or the dinosaur script/noscript parardigm - the choice must be offered to users, upfront.

    Copy & paste the code below to embed this comment.
  14. I to can not wait for the follow up to this story I have always been a fan and passionate aboutlearning AJAX and plan on making all my site using it. A really great read!

    Copy & paste the code below to embed this comment.
  15. Like some others, I was pretty frustrated with the fact that most of the article was not showing me how to make AJAX work, so I figured out the basics of what was missing.

    I think it’s fine that the data store is not mentioned; this is not a tutorial on how to use a database (or whatever). I used a quickie mySQL database, and interacted with it using PHP. To make it work, you have to make a PHP script which echos (literally, using that keyword) any data to be sent back to the AJAX. That handles all the database connection and everything else. If you’re smart, you might make it execute some PHP which isn’t web-accessible, as it will contain your database password. Anyway.

    Keep his directory structure (for now): have the XHConn.js, your custom addressbook.js, your PHP page and your other PHP script(s) all in the same directory. Set up your page the same way he does, with the same names on the Submit button and so forth. You need to change this line:
    addressBook.myConn.connect(‘index.php’, ‘POST’, ‘id=’+id, fnWhenDone);
    The index.php must be changed to reflect the name of the PHP script which echos back the data.

    Apart from that, that’s about it. It should work from there (at least with the string version; I haven’t yet delved into the XML stuff). To have a look at some code, check out http://www.robertgrant.org/addressbookdemo - it doesn’t work, because I’m not going to let you see my password, but you can easily adapt it, I’m sure. Database layout can be inferred reasonably simply, as can my average mySQL+PHP abilities.

    If you want a more step-by-step article, take a look at my website; there’s an article on AJAX there. (If advertising this is a problem mods, please delete this paragraph. Sorry if it is, but I thought it might be helpful!)

    Copy & paste the code below to embed this comment.
  16. I think all of us here would love to be able to design and develop with pure accessibility in mind plus be able to use ‘kewl’ features. But often this is not possible (especially in the real world). I do think however that we can be a little lapse on accessibility where it is acceptable to introduce features that would improve the user’s experiance as long as it is done so the user has a choice.
    What does annoy me is the blantant over use of Ajax where it is not required or could of been better implemented. But that is not a good reason to say ‘never’ but to take it upon ourselves to ensure we provide the knowledge for it to be use right. There is never to many tutorials especailly good ones. I for one enjoyed this tutorial even though I have spent the last few weeks reading everything i can find in books and on the internet about the subject.

    Copy & paste the code below to embed this comment.
  17. hi how do i get the data into my ajax example, xml or sql database? how do i do it with this demo?
    Gparty

    Copy & paste the code below to embed this comment.
  18. Have you tried looking at the example I gave 2 posts above yours? It might help.

    Copy & paste the code below to embed this comment.
  19. Complete websites in Flash drive me around the bend for obvious reasons.  Standards, usability, accessibilty.  But when flash is used sparingly and cleverly it can be an amazing edition to a website.  Is it not the same with AJAX? 

    Why on earth would you rely on this technology 100% for your web app when it could be used to enhance site features developed in tandem with other approaches rather than being the silver bullet.

    Copy & paste the code below to embed this comment.
  20. I hope that the browser is required to send a browserID

    if (browserID.name & browserID.verson) = IE.8.1
    render(ASCII)
    else
    render(HTML,CSS)

    Just messing with you head, that would be just too easy

    Copy & paste the code below to embed this comment.
  21. Is it just me or are there others who believe this script has no accessibility issues whatsoever?

    After all, the HTML document contains a regular HTML form with a regular POST going to a page containing the looked-up address.
    Users with accessibility issues (the blind or in any other way limited, this includes search engines) visiting this page will get that good’old FORM with a regular post and no accessibility issues here.
    It’s only the browsers that have javascript enabled that would have all of this AJAX-code executed (Aaron checks for this from line 12 of his example).
    Allright there’s the “back-button” thing.  But that’s why this is “getting started” and not “how to perfect”.
    And allright the “second page” (after the post of the regular form) ain’t here. But that’s an obvious thing, right?

    As long as developers create their application the old way first (get, post, regular scripts aso) and only then improve the site with ajax techniques, there’s no problem.

    Concerning the nonstandard XMLHttpRequest, I raised an eyebrow here too.  It reminded me it’s nonstandard.  I’m hoping the WaSP and others fight for us to get this as a strong and documented standard in every webbrowser to come SOON! I’m scared of investing my time in a technique that has not been adopted by every browser developer and thus might be replaced with something else/better, though I do believe AJAX is worth the investment.

    Aaron, thanks for the article.  Excellent work.  Nice meeting you too.

    Copy & paste the code below to embed this comment.
  22. bq. After all, the HTML document contains a regular HTML form with a regular POST going to a page containing the looked-up address. Users with accessibility issues (the blind or in any other way limited, this includes search engines) visiting this page will get that good’old FORM with a regular post and no accessibility issues here. It’s only the browsers that have javascript enabled that would have all of this AJAX-code executed (Aaron checks for this from line 12 of his example). Allright there’s the “back-button”? thing. But that’s why this is “getting started”? and not “how to perfect”?.

    Funny, that’s just what I was about to say.

    As for your request about standardization of XMLHttpRequest(), I think we’ll be seeing that in the _very_ near future.

    And it was a pleasure meeting you as well. Hopefully we’ll meet again one day… maybe even in Belgium ;-)

    Copy & paste the code below to embed this comment.
  23. After all this discussion of separating presentation from content, it’s disheartening to see so many styles set in the behavior:


    // give it some style
      addressBook.loader.style.position   = ‘absolute’;
      addressBook.loader.style.top     = ‘50%’;
      addressBook.loader.style.left     = ‘50%’;
      addressBook.loader.style.width     = ‘300px’;
      addressBook.loader.style.lineHeight = ‘100px’;
      addressBook.loader.style.margin   = ‘-50px 0 0 - 150px’;
      addressBook.loader.style.textAlign = ‘center’;
      addressBook.loader.style.border   = ‘1px solid #870108’;
      addressBook.loader.style.background = ‘#fff’;

    Wouldn’t it be an improvement to assign a class or id through the JavaScript instead, and move the style rules to the style sheet?

    Copy & paste the code below to embed this comment.
  24. Sitting here at Microsoft Mix 06 and saw a great presentation about the Atlas platform. If you are interested in AJAX development, you should take a look at this. http://atlas.asp.net

    Dale

    Copy & paste the code below to embed this comment.
  25. Check out Hijax, a technique for progressive enhancement with Ajax:

    http://domscripting.com/blog/display/41

    There is also a good discussion of related usability issues. Note the comparison of GMail vs. Backpackit.

    Lindsay McLennan (prefers PSV to Ajax)

    Copy & paste the code below to embed this comment.
  26. I still have to duck deeper in Ajax but for now it looks very good. The possibility’s seem to become endless for building webpages nowadays. :)

    Copy & paste the code below to embed this comment.
  27. In response to “Janette”:http://www.alistapart.com/comments/gettingstartedwithajax?page=3#23, I go back and forth about seperation of script from presentation. In some cases, it makes sense to set only classes in a script and in others it makes sense to actually apply style via script. I think it is something that needs evaluation on a case-by-case basis. In the case of the “loading” notification you mention, I didn’t see the purpose of adding those minor styles to a seperate style sheet (which would complicate an example on a completely different topic). Were I dealing with a lot of scripted elements which needed style (as in the case of some projects I am working on now), I would actually have a special ria.css file—RIA standing for Rich Internet Application—which is added to the document _by the JavaScript_. In other words, the script carries its styles with it and those styles are only applied if the script actually runs, thereby seperating the styles for the website in question from the script-specific styles and making overall CSS- and JavaScript-management easier.

    Copy & paste the code below to embed this comment.
  28. Thanks, Aaron.  This article was exactly the thing I needed to be “getting started with Ajax”.  I use some generic scripts to list x records from a table, with next/prev page links at the bottom, and I’ve been wanting to have it update only the data table, and not the entire page.  After reading this article, I was able to do just that.

    The big thing for me, though is the fact that this article is a perfect example of what Jeremy calls HIJAX:  the page still works without javascript, but WITH javascript, it allows for a “Web 2.0” application.

    OK, on to accessibility issues with ajax.  For people using screen readers who also have javascript turned on, when the document itself changes like this due to ajax, the screen reader isn’t aware of it.  One solution would be to give screen reader users a link to disable the ajax effect, essentially turning the web app into a Web 1.0 app for them.

    Wouldn’t it be nice if there were a Browser Object Model (BOM) we could interrogate to find out if a screen reader is in use?  With this, we could automatically disable the ajax effect, leaving the user in Web 1.0 mode.  This BOM could even let us know which plugin was (or would be) loaded to handle a particular mime type, etc.  I’m sure there are other things the BOM could do for us, but these two issues came to my mind first.

    Copy & paste the code below to embed this comment.
  29. Great tutorial, hey man and other followers, I have a site that is giving forum based classes on PHP, MySQL, Linux, Apache, JavaScript and most importantly <a >AJAX</a>.

    I would love to have you guys come check it out learn, and actually give some of your lessons and tutorials on the forum for others to learn and read about it, feel free to use your blog address as a sig when you post new lessons or questions and comments.

    I just put up my first lesson, in creating a Shout Box in <a >AJAX</a> so come check it out.

    Grim1208
    <a >LAMP Geekz</a>

    Copy & paste the code below to embed this comment.
  30. Hi! Thank you for these valuable informations…
    Greetings from Germany

    Sam.

    Copy & paste the code below to embed this comment.
  31. The innerHTML method isn’t a part of the DOM specification, but it’s available in Mozilla, IE and Opera. I know for the first two from experience, and the Opera website says it’s supported.

    Copy & paste the code below to embed this comment.
  32. I can read XHTML/CSS with no problem.  I can read PHP with some effort.  For some reason, JavaScript and AJAX are just so dense, that no matter how I try, my eyes start to blur over!

    I would love to learn the technology, but man, it seems so dense!

    Copy & paste the code below to embed this comment.
  33. Can anybody tell me how can i make application like google suggest in ASP.Net??

    Copy & paste the code below to embed this comment.
  34. Before reading this article, I just heard of this name AJAX, but know nothing about it.

    Aafter reading, understand a little and maybe will like this new tech.

    Copy & paste the code below to embed this comment.
  35. Didn’t find any implementations of the index.php, so if some are interested, here is mine:

    <?php

    // Change the header to display Javascript..
    header(‘Content-type: text/javascript’);

    // Check to see if there is a id variable sent..
    if ( $_REQUEST[‘id’] ) {

    // Converted id to a regular php variable..
    $id = $_REQUEST['id'];

    // Print out the returned value..
    print "You sent id: " . $id;
    } else {
    // No id variable recived..
    print "No id sent";
    }

    ?>

    Copy & paste the code below to embed this comment.
  36. So far I am not convinced to introduce Ajax in my web application. Great web sites are about accessibilty and functionaly - not fancy extra features

    Copy & paste the code below to embed this comment.
  37. Sorry, commenting is closed on this article.