I'm not sure what you mean by "javascript form generated by AJAX" -- is it possible that you are generating a form in the DOM with javascript then doing a regular submission with it by clicking (via javascript) a button? If so, then it's not being submitted via AJAX, but rather as a normal post. The beforeSend handler is only invoked when the form is submitted via AJAX. Your set up call is adding a default beforeSend function that sets the Accept header so that javascript is returned, but it only does so on requests submitted via AJAX.
This is what an AJAX submission looks like:
$.ajax({
url: '/controller/action',
type: 'post',
dataType: 'json',
data: $('form').serialize(), // this gets the form data
success: function() {
},
...
});
This is a javascript-created form and submission (non-AJAX).
$('<form><input type="hidden" name="inp" value="somedata" /></form>')
.appendTo(document.body)
.submit();
or (via a button click)
$('form #submitButton').click( function() {
$('form').submit()
});