How to get Ajax to load first?
It could help.

add php function: 

use Drupal\Core\Ajax\AjaxResponse;

Class AnyClass extends FormBase {

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

/**
 * Running the library drupal core ajax
 */
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';


}

}