Simple AJAX Steps for Success

We are doing a ton of AJAX work with [AO]. Here are 10 helpful hints if you are considering using AJAX in an upcoming project:

  1. You don't need an AJAX library 
  2. Download [Aptana]. Make it your default .js editor inside Visual Studio.
  3. Place all Javascript in external files (like codebehind)
  4. Instead of making invoking requests directly from your pages, build a class library that does the dirty work.
    hint: once you have these base libraries, add the files the code assist window to get auto-complete inside [Aptana]. [Aptana] lets you add documentation comments as well as parameter and return type information. Use it!
  5. You don't need an AJAX library.
  6. You can make classes in Javascript too.
  7. You don't have to define seperate functions for async callbacks from webservices. Use anonymous methods to inline your code in the calling method.
  8. Consider providing ways to extend standard HTML elements rather that trying to make up all sorts of funky controls. Controls have a place, but consider the common example of a grid. A grid is really just a table. Don't create a grid class, provide a way extend the table and add column sorts, row hover handling, row selection, etc. to it. Then, you can use standard HTML layouts and design and simply call a function or two to inject the features you want.
  9. Make sure to secure your AJAX server side.
  10. You don't need an AJAX library.

Why do I point out over and over that you don't need an AJAX library? Because all the AJAX hype out there makes the problems out to be a lot more difficult than they are. I would recommend one little script to abstract away SOAP or JSON requests, since you probably don't want to build that manually, but you don't really need much else to get started building AJAX into your applications. The most important thing to do is get a solid understanding of Javascript and CSS and make sure that you use standard DOM properties as much as possible. A great editor like [Aptana] can also be an extremely valuable tool. This isn't to say that using an AJAX library is a bad thing, just that you can get by fine without one if you would rather not add the extra dependancies and complexity to your app. The browser differences are not nearly as bad as the mobs might have you believe.

Also keep in mind that you don't have to make every element clickable and every node draggable. Web apps are not windows apps. You don't need one base page that everything is dynamically added to and removed from. On the contrary, it is nice to have back and forward buttons that actually do something. A lot of improvement can be made by simply adding a few AJAX callbacks to eliminate those annoying pages you used to have to make with 2 lines of text and a button.

12 Comments

  • Whilst it is straightforward enough to knock-up your own cross-browser Javascript and use XMLHttp to achieve some 'Ajax effect', it's a different thing entirely to build your own Ajax library with everything that comes with it like JSON request and response generation, client-side web service proxies, event hookups etc.

    It's worth looking into the Javascript Atlas library scripts because writing a complete Ajax library is not as trivial as you make it out to be.

    I'm currently toying with the Atlas scripts, without any use of ASP.NET 2.0 and Atlas server controls. It's worth for people to familiarize themselves with if you're serious about Ajax development, you want a decent set of Javascript libraries and you've seen all the tricks of the Atlas UpdatePanel server control.

    To browse the full Atlas library hierarchy and its controls, I suggest people visit: http://atlas.asp.net/docs/Client/Browser/jsBrowser.aspx

    Hours of fun guaranteed...

  • My point is not that making a complete AJAX library is trivial. My point is that most people don't need a complete AJAX library just to add a little spice to their applications. Most people don't need the option to do both JSON requests and SOAP requests. Most people don't need the ability to make calls to webservices on other domains via proxies. Most people don't need all the junk that these libraries include.

    However, as I mentioned in my post, I'm not saying that a library like Atlas is bad (in fact, I am looking forward to using Atlas when it finally goes live). What I am saying is that to get started using AJAX in your applications, you certainly don't need to learn how to use a big beefy library like Atlas or Dojo and build all sorts of dependancies to it into your application.

  • That's fair enough.

    But for people looking to add some 'Ajax spice' to their applications that are using ASP.NET 2.0, the Atlas server controls like UpdatePanel and the Atlas Extender control will more than likely suffice.

  • I agree. As soon as Atlas is released it will be the best solution. But it's still in beta. I would have liked to use it for my projects, but we certainly aren't going to build a product on top of a beta... especially one from MS, who has been notorious for removing features from products lately.

  • я считаю: мне понравилось! а82ч

  • hmm... cognitively thread :)

  • VQ6ldN I appreciate you sharing this blog.Much thanks again. Great.

  • H6dOuu Really enjoyed this blog.Much thanks again. Great.

  • E3snwG Wow, great blog.Much thanks again. Really Cool.

  • mm9Bik Enjoyed every bit of your blog article.Much thanks again. Fantastic.

  • zJIhwJ Very good article.Thanks Again. Will read on...

  • apgNnf Thanks a lot for the article.Really looking forward to read more. Much obliged.

Comments have been disabled for this content.