views:

441

answers:

12

I'm building a web application with the Zend Framework. I have wanted to include some AJAX type forms and modal boxes, but I also want my application to be as accessible as possible. I want my application to be enhanced by AJAX, but also fully functional without AJAX.

So as a general guideline...when should I not use AJAX? I mean, should I bother making my application usable without AJAX? Or does everyone have AJAX enabled browsers these days?

+6  A: 

Use ajax if it adds value for the user.

If the ajax version adds a lot more value than the non-ajax version then it might justify the expense to develop a solution that caters for both clients. Generally i wouldn't recommend doing the extra work (remember.. more code results in more maintenance).

cottsak
The optimal amount of code is no code, so I agree with cottsak: use ajax only if it adds real value for the user.
hora
+4  A: 

98% of users will have AJAX enabled browsers.

A significant percentage of those people won't have it turned on when they first visit your site though (or at all, ever perhaps).

I've seen websites that look like a blank page without javascript on. Don't be one of them. Javascript to fix layout issues is a horrible idea in my opinion. Make sure it loads and looks ok without Javascript. If people can atleast see what they are missing out on, they are likely to switch it on, but if your website looks like it's just broken, then...

Matthew Scharley
Define "A significant percentage." According to w3schools, as of January 2008, only 5% of users didn't have JavaScript enabled http://www.w3schools.com/browsers/browsers_stats.asp and I suspect that you will see that number decrease a little this year. Also, demographic is an important thing to consider. If the OP is not targeting developers and the otherwise paranoid, chances are good that JavaScript is enabled.
Justin Johnson
5% is a significant number in most circles. If you had to pay me 5% of your income, I'm sure you'd start complaining pretty quickly.
Matthew Scharley
As a more solid example though, only 10% of users (by the same stats) use either Chrome or Safari (~5% each), but where I work we test both those cases too.
Matthew Scharley
+1  A: 

Unless you are targeting mobile devices or other non-standard web users, you can be fairly sure that the vast majority has Javascript enabled, because most major sites (including SO) rely heavily on it.

Manu
A: 

My practice is to use two main pages, let's say index.py and ajax.py. First one is responsible for generating full website, and is default target of forms. Other one generates only output specific for adequate ajax query. Logic behind both of them is the same, only the method of generating output is a bit different. In jquery I simply change action parameter when sending a request. It works both with and without ajax, although long time have I not seen someone with disabled js and ajax.

raceCh-
+2  A: 

I often have noscript block Flash and JavaScript until I make the decision that your site is worthy.

So be sure to tell me what I'm missing if I have JavaScript turned off.

Nosredna
Would you mind showing some example code of how you detect if the user has purposefully disabled javascript?
Andrew
Since you don't have JavaScript running, you can't use JavaScript to check. Instead, take a look at the HTML noscript tag.
Nosredna
+7  A: 

If you mean "accessible" in the ADA sense, AJAX is usually a no-no - your site should provide all its content and core functionality using only standard (X)HTML and CSS. Any javascript used should merely extend the core functionality, and your site should be coded to work elegantly in the absence of a javascript-enabled browser.

Examples: if you want a user to click on a thumbnail and get a full-size version of the image as a result, you can make the thumbnail a link. Then, the onclick event will fire a JQuery method that cancels the navigation behavior of the link and pops up a JQuery floating div to show the image on the current page. If the user's browser doesn't support JavaScript, the onclick event will never fire, and the user will be presented the image in a new page. The core functionality is the same with or without scripting.

EDIT: Skeleton example, sans JQuery-specific code.

<html>
<body>
<a href="some.url" onclick="JQueryToOpenPopupImage(); return false;">Some URL</a>
</body>
</html>

To cancel the navigation operation, simply make sure that the method invoked by the onclick event returns false at the end.

A neat example of the JQuery image popup I described can be found here.

Dathan
Would you mind showing some example code of how to disable the click and do something else with jQuery, like you mentioned?
Andrew
Alright, I've posted an update to my answer.
Dathan
You can actually use http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29 . Javascript code in onClick is harder to manage.
Maiku Mori
A: 

I like the thought of coding your application without JavaScript / Ajax and then adding it in later to enhance the UI without depriving users of functionality just because they don't have JavaScript enabled. I read about this in Pro ASP.NET MVC but I think I've seen it elsewhere in reading about unobtrusive JavaScript.

Mayo
A: 

You should not make your service bloated with web 2.0 effects like accordion, modal/etc forms, image zoomers etc.
Use modern tech smarter (AJAX is one of them) and your users will be happy. Do not fear AJAX -- this is very good thing to make user expirience smooth. But don't do things because you like it - do them because your user need it ;)

NilColor
+1  A: 

It depends on the complexity of your web application.
If you can, having it functional with javascript disabled is great, because it makes your application usable not only by users on js-disabled browsers but also by robots. The day you decide to write an application to automatically fill your forms, for example, you don't have to write an API from the ground up.

In any case, do not user AJAX for EVERYTHING! I have just inherited a project that basically consists of a single page that is populated by a ton of AJAX calls and I can tell that you just thinking about it gives me physical pain. I guess the original developer didn't like the concept of using the back/forward button in the browser as a mean of navigation.

Loris
+3  A: 

I think one point is missing here: Use Ajax only for content any search engine does not need to know.

Hippo
A: 

When you want to make a website that looks like a website, not a fugly imitation of a desktop app?

Igor Zevaka
A: 

You should not use AJAX or JavaScript in cases where:

  • your system needs to be accessible
  • your system needs to be search friendly

However, by using a modern JS framework with some solid "unobtrusive" practices, you can progressively enhance pages so that they remain accessible and search-friendly while offering a slick UI to users.

Toby Hede