It seems, I found some solution, may be not fully drupal-way.
Firstly, we need to load JS libraries, needed for working of ajax submit. This code helps us:
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'drupal.form');
drupal_add_library('system', 'jquery.form');
drupal_add_library('system', 'druapl.progress');
drupal_add_library('system', 'drupal.textarea');
Nextly, we need to fill JS class Drupal.settings.ajax with data about page elements, which provides ajax behavior. I have not an universal solution, I only stops JS code on breakpoint in misc/ajax.js when running it on page with correct working ajax form. You can see correct values in this part of code:
Drupal.behaviors.AJAX = {
attach: function (context, settings) {
// Load all Ajax behaviors specified in the settings.
for (var base in settings.ajax) {
if (!$('#' + base + '.ajax-processed').length) {
var element_settings = settings.ajax[base];
if (typeof element_settings.selector == 'undefined') {
element_settings.selector = '#' + base;
}
$(element_settings.selector).each(function () {
element_settings.element = this;
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
});
$('#' + base).addClass('ajax-processed');
}
}
So, in my case resulting JS code, needed to be added into startup javascript, looks like this:
if(Drupal.settings.ajax == undefined){
Drupal.settings.ajax = {
'edit-submit': {
callback: "faqform_ajaxsubmit",
event: "mousedown",
keypress: true,
prevent: 'key',
submit: {
_triggering_element_name: "op",
_triggering_element_value: "Send"
},
url: 'system/ajax',
wrapper:'submit-message'
}
};
}
If all done correctly, you form, loaded by ajax, will have correct ajax behavior, in my case - ajax submit.
May be there are more graceful solutions, may be diving deeper into code will help you to find them.