tags:

views:

167

answers:

8

It seems that the sites and applications that use AJAX are growing rapidly. And probably one of the major reasons for using AJAX is to enhance the user experience. My concern is that just because the project CAN use AJAX, doesn't mean that it SHOULD.

It could be that AJAX is exposing more security threats to the site/app for the sake of UX. Maybe you have other reasons for not using AJAX.

When should the use of AJAX be avoided?

+3  A: 

You definitely should avoid AJAX when you are sure that your clients will be using "not javascript enabled" browsers

nairdaen
+1  A: 

If your development time is limited or your team lacks sufficient expertise, then you could make a good case for staying away from AJAX programming.

But otherwise:

[AJAX calls are] no more-or-less safe than a normal HTTP POST request issued by a browser as in from a -form-.

The "fix" for this is the same "fix" for non-AJAX requests - use SSL.

Jim G.
+1  A: 

I hear this a lot - just because you can make it pretty with Ajax doesn't mean you should.

I don't think you should necessarily put the UI on the backburner though. It shouldn't be the last thing you think about, particularly in certain cases.

The UI is what the user sees - they don't see any of the complexity behind it, so they'll judge the quality of your site/application based on how easy it is to use and how it makes sense to them.

With that in mind, decide on Ajax based on the user's point of view. Does it make sense that when I click on this button the page slides to the left to reveal a new section? Would it comfort me or confuse me to see the page grayed out and a "Working..." image displayed in front?

Damovisa
+3  A: 

Actually, AJAX should be used to enhance user interaction. If not it, then Flash or what have you.

Naturally, if there's no possible enhancement, there's no reason to go that way. I tag that as highly unlikely. If you find such a case, blog about it: it'll probably make interesting read.

There are situations, of course, where AJAX is contra-indicated. Basically, when you don't have people using the site. If you expect the site to work with SOFTWARE driving the requests, then you must make sure it works fine without AJAX.

And if you don't expect software to drive the requests, I sure hope you have an alternate API for it, one that can do everything the site can. Otherwise you are just deluding yourself and failing your clients.

Daniel
+3  A: 

Getting Data Already Available Or Data Easily Obtainable

I usually see that on car websites, where there are makes and models. Their usual <select> (without JavaScript) include <optgroup>'s as such:

<select>
    <optgroup label="Ford">
        <option value="21">Escape</option>
        <option value="21">F-150</option>
    </optgroup>
    <optgroup label="Toyota">
        <option value="51">Corolla</option>
        <option value="52">Yaris</option>
    </optgroup>
</select>

Then usually then proceed to hide that <select> and create 2 new select, one for makes and one for models.

All is fine up to that point. They start messing up here.

They then process to query the server to get a list of makes, and then do another query to get the list of models, when they could of simply parsed the original element try to get their information. Then, everytime you change make, another request is made...

The above is a excellent example of when NOT to use AJAX. Consider this: a request is longer than parsing available data, so they make the user wait. They probably query their database each time, so it has a hit on their server CPU usage. And it incurs more bandwidth. Terrible waste of resources.

What they should have done

They should of have simply parsed the DOM try under the <select> to fetch the relevant information. Each <optgroup> is an item in the makes <select> while each child <option> from the <optgroup> is an item in the models <select>.

Other examples

  • Using AJAX for simple static DOM modifications (you don't need AJAX to switch from one tab to another in most cases, just include the data in your original request).
  • Using AJAX to retrieve data on load (why not include it with the original request?)
  • Using AJAX for an image gallery (why not include the images and manipulate them after the request is done?)
Andrew Moore
A: 

It could be that AJAX is exposing more security threats to the site/app for the sake of UX. Maybe you have other reasons for not using AJAX.

How? What security threats?

ceejayoz
+1  A: 

When redirecting a user to a new page which the user might want to bookmark - i.e. if clicking on a link causes the content to be updated using AJAX, the user can't bookmark the page.

Ankur
Using AJAX does not preclude bookmarkability. Updating the URL appropriately is a separate, but valid concern.
Duncan Beevers
+1  A: 

AJAX should be avoided when the same functionality can be implemented entirely client-side without an additional round-trip to the server.

For example, it may be more efficient to seed the client with a list of zip codes for all US States and scope zip code selection to the appropriate set rather than going to the server for a list of valid zip codes for the given state.

Duncan Beevers