Load form via ajax and submit by ajax not working I have loaded a form via ajax and submit by ajax not working. But if I load form directly by url ajax submission is working. Form is loaded by ajax is using jQuery.

$('#button').on('click', function () {
        $.ajax({
            url: "user_group/edit_ajax/", 
            success: function (result) {
                $(".RblockMain").html(result);
            }
        });
});


mymodule.routing.yml 

mymodule.user_group_edit_ajax:
  path: 'user_group/edit_ajax/'
  defaults:
    _controller: '\Drupal\mymodule\Controller\UserController::user_group_edit_ajax'
  requirements:
    _permission: 'access content'


UserController

public function user_group_edit_ajax() {
        $form = \Drupal::formBuilder()-&gt;getForm('Drupal\mymodule\Form\UsergroupForm');

        $body_data = array(
            '#theme' =&gt; 'usergroup_edit_ajax',
            '#usergroup_form' =&gt; $form,
        );

        $message = \Drupal::service('renderer')-&gt;render($body_data);
        $response = new AjaxResponse($message);
        return $response;
    }


UsergroupForm.php

class UsergroupForm extends FormBase {

   public function buildForm(array $form, FormStateInterface $form_state) {

    $form['user_group_name'] = array(
          '#type' =&gt; 'textfield',
          '#title' =&gt; '',
          '#required' =&gt; TRUE,
          '#attributes' =&gt; array('placeholder' =&gt; t('Group Name'),),
          '#theme_wrappers' =&gt; array(),
        );

    $form['go'] = [
      '#type' =&gt; 'button',
      '#value' =&gt; $this-&gt;t('Submit'),
      '#attributes' =&gt; array('class' =&gt; array('btn btn-primary'),),
      '#ajax' =&gt; [
        'callback' =&gt; array($this, 'submitForm'),
        'event' =&gt; 'click',
        'progress' =&gt; ['type' =&gt; 'throbber', 'message' =&gt; NULL],
      ],
    ];
    }

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
 $title = $form_state-&gt;getValue('user_group_name');
$data = array(
        'type' =&gt; 'admin_user_group',
        'title' =&gt; $title,
        'uid' =&gt; 1,
        'status' =&gt; TRUE,
      );
      $usergroup = \Drupal::entityManager()-&gt;getStorage('node')-&gt;create($data);
$usergroup-&gt;save();
$response = new AjaxResponse();
    $response-&gt;addCommand(new AlertCommand('Submitted successfully'));

    return $response;
}
    }
I had the exact same issue: 

When the form was on its own page, ajax submit works.

When the form was loaded through ajax, ajax submit didn't work, submit was redirecting the form to its own page.

After unsuccessfully restarting from scratch twice, I tried to implement this ajax modal example: https://www.mediacurrent.com/blog/loading-and-rendering-modal-forms-drupal-8/

Success one.

Then removing the openModalCommand to simply display the form on the page.

Success two.

I compared both my unsuccessful attempts and the successful one.
There was one difference, in the success one, in the controller the form was built but not rendered.

// Controller to load the form through ajax
public function ajaxSupportTicket() {
    $form = \Drupal::formBuilder()-&gt;getForm('Drupal\itportal_support\Form\SupportTicketForm');
    $ajax_response = new \Drupal\Core\Ajax\AjaxResponse();

    // Append the form in the page.
    // The form is sent as is, not rendered
    $ajax_response-&gt;addCommand(new \Drupal\Core\Ajax\AppendCommand('#selector', $form));


    return $ajax_response;
}


Now that this works, the whole ajax api of D8 seems very powerful.

Also, try to get rid of your custom javascript to load the form. It can be done using render array. Place a link with use-ajax class.

$output['open_form'] = [
  '#type' =&gt; 'link',
  '#title' =&gt; $this-&gt;t('Open Form'),
  '#url' =&gt; Url::fromRoute('mymodule.ajax_form_controller'),
  '#attributes' =&gt; [
    'class' =&gt; [
      'button',
      'use-ajax',
    ],
  ],
];

// Attach the library for pop-up dialogs/modals.
// drupal.dialog.ajax might be overkill, but I didn't took time to improve
// comments about it are welcome
$output['#attached']['library'][] = 'core/drupal.dialog.ajax';


Hopefully, it can help.