I tend to use both options where a full page refresh from a regular <form>submit works, but if JavaScript is enabled, you hook into the submit event and override it. This gives you bizarre AJAX, if possible, and graceful deterioration, if it is not.
Here is a quick example (jQuery for short):
<form type="POST" action="myPage.htm">
<input type="text" name="UserName" />
<button type="submit">Submit me!</button>
</form>
If the user does not have JavaScript, the problem does not occur. If they do (and most of them), I can do this:
$(function() {
$("form").submit(function() {
$.ajax({
url: this.action,
type: this.type,
data: $(this).serialize(),
success: function(data) {
}
});
});
});
This allows you to decompose gracefully, which can be very important (depending on your attitude / client base, I suppose). I try not to screw users without JavaScript, or if a JavaScript error occurs on my part, and you can see from above, this can be done easily / in general, so as not to be painful.
, X-Requested-With , , <form> - ( AJAX) , .