Ajax Forms created by Ajax Drupal 7 ERROR JAVASCRIPT I read a lot of documentation, specially this post https://www.drupal.org/node/2009252 but doesnt work for me. 

This is my code, and the main problem is that i dont get the javascript in function hcat_my_account_create_companion_ajax_callback from the page callback 'my-account/ajax/create-companion' then I cant send my form by ajax.

function hcat_my_account_menu() {
    $items = array();

    $items['my-account/ajax/create-companion'] = array(
        'page callback' =&gt; 'hcat_my_account_create_companion_ajax_callback',
        'access callback' =&gt; TRUE,
     );

    return $items; 
}

function hcat_my_account_create_companion_ajax_callback($form, &amp;$form_state) {  

    $submission = (object) array();
    $form = render(drupal_get_form('hcat_my_account_acomp_form', null, $submission, true, false));

    $settings = FALSE;
    $javascript = drupal_add_js(NULL, NULL);
    if(isset($javascript['settings'], $javascript['settings']['data'])) {
        $settings = '&lt;script type="text/javascript"&gt;jQuery.extend(Drupal.settings, '.drupal_json_encode(call_user_func_array('array_merge_recursive', $javascript['settings']['data'])).'); console.log("He cargado el Drupal.settings");&lt;/script&gt;';
    }

    form_load_include($form_state, 'inc', 'node', 'node.pages');
//I CANT PASS ANY JAVASCRIPT. WILL DISAPPEAR.
    return "&lt;div id='new-form-ajax'&gt;".$form.$settings."&lt;/div&gt;";
}

function hcat_my_account_acomp_form($form, &amp;$form_state, $vars) {

    $form['hola'] = array(
        '#type' =&gt; 'textfield',
        '#default_value' =&gt; "Vamos",
        '#attributes' =&gt; array('class' =&gt; array('my-account-input-edit')),
    );
    $form['submit_save'] = array(
          '#type' =&gt; 'submit',
          '#value' =&gt; 'Vamos que te quda poco',
          '#ajax' =&gt; array(
                'callback' =&gt; "hcat_my_account_create_attend_form_submit_ajax",
                'wrapper' =&gt; "hcat-my-account-acomp-form",
                'method' =&gt; 'replace',
                'effect' =&gt; 'fade',
              ),
    );

    form_load_include($form_state, 'inc', 'node', 'node.pages');

    return $form;
}

function hcat_my_account_create_attend_form_submit_ajax($form, &amp;$form_state) {
    return "Desde la funcion hcat_my_account_create_attend_form_submit_ajax";
}
I found this way to resolve it. Creating another form whose submit return the form that i want. The code is:

function my_module_botton_create_form($form, &amp;$form_state) {
    $form['create_form'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; '',
        '#ajax' =&gt; array(
            'callback' =&gt; "my_module_to_create_form",
            'wrapper' =&gt; "new_acomp_form",
            'method' =&gt; 'replace',
            'effect' =&gt; 'fade',
          ),
    );

    return $form;
}

function my_module_to_create_form($form, &amp;$form_state) {

    $form=drupal_get_form("my_module_acomp_form");

        $output = array(
            '#type' =&gt; 'ajax',
            '#commands' =&gt; array(
                array('command' =&gt; 'ajax_create_form_acomp', 'data' =&gt; drupal_render($form)),
            ),
        );

        return $output;
}

function my_module_acomp_form($form, &amp;$form_state) {

    ...

    return $form;
}


The JS is

Drupal.ajax.prototype.commands.ajax_create_form_acomp = function (ajax, response, status) {
    $('#new_acomp_form').replaceWith(response.data+"&lt;div id='new_acomp_form'&gt;&lt;/div&gt;");
    //Drupal.behaviors.hcat_my_account.check_if_attendant_exits();
};