Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Which is better and why?

I can see where a site that works 100% in AJAX might optimize a bit better, due to not having to reload the page on each click.

But I am a huge fan of the big submit button at the bottom of the screen.

Is it worth spending the time to convert a site to AJAX when it mostly only optimizes page load times?

share|improve this question
add comment

4 Answers 4

up vote 6 down vote accepted

In most cases, you need to have the manual submit, even when you've utilized AJAX to submit your forms. JavaScript is not always enabled for a variety of reasons. Most text-only browsers usually don't interpret JavaScript and so it's important to have a fallback. Also, although I know it's not applicable for most forms, search engines have very limited ability to parse and execute JavaScript, so it's best not to use it to construct menus.

Is it better to enhance a form with AJAX? It depends on your situation and also on your implementation. If all you're doing is an AJAX form submission, I'd recommend against the extra 20K overhead of a JavaScript framework like jQuery or MooTools. In that case, use pure JavaScript. However, if you're using the framework elsewhere as well, it could be a good choice. Just be aware that using AJAX can present a number of usability issues (like the back button behavior).

Also, just as a warning and friendly reminder, don't just do your validation with JavaScript. It needs to be done on the server, first and foremost. Use the JavaScript to enhance the security, not to provide it.

share|improve this answer
    
Agreed. The idea of "progressive enhancement" applies here, so that you should use AJAX to enhance a process, not replace it. –  Dan Diplo Aug 1 '10 at 10:36
    
Actually, in AJAX session cookies+XSRF validation avoids the back button issue. With a POST submit this is unavoidable. –  Talvi Watia Aug 1 '10 at 21:28
add comment

Neither is really better than the other. It's a matter of preference for the most part. Do you want to reload the entire page, or just reload a certain portion of it. If the form is all you're showing, ajax is probably slower than reloading the page. However, if your form is just a small portion of the page, ajax would probably be faster.

You can still have a big submit button. Just don't make it submit. Catch it's onclick event, do your ajax thang, and return false.

Check out jQuery for some pretty painless ajax stuff.

share|improve this answer
1  
+1 you'll have a POST either way but with a traditional submit you don't have the added overhead of parsing javascript, unless you have a client-side validator or something. Granted that's client side. When developing I make the call mainly with user experience in mind. –  squillman Aug 1 '10 at 4:51
    
Agreed. It really comes down to UX at that point, if you're able to do either. –  hookedonwinter Aug 1 '10 at 7:43
add comment

The issue you should consider is the user's experience and how it relates to conversion.

If using AJAX create a better experience for your users and helps them convert, you should probably use it.

A simple example: your user chooses a user name. The user name is already taken. Using AJAX to check in the background and letting him know right then and there is much better than letting him complete the form and reload the page.

Most of the time, I find that AJAX improves things.

share|improve this answer
add comment

They are not mutually exclusive: with progressive enhancement you can use both!

Start with a basic form that submits via POST, and write some server-side code to handle that and redirect back to the previous page, which will now be updated. This covers the accessibility and no-JS sides.

Next, add your AJAX code to the page, that "hijacks" the onsubmit event for the form, call your AJAX function that runs the same server-side code to process the submission, but this time returns some data that tells you how to update the page. Don't forget to return false from your JS function so that the form is not posted in the normal way.

Now you have the "faster" experience for the majority of users, and still have the functional experience for everyone as a backup.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.