How to have the autocomplete option with ajax in a text field?
You need to filter the user input and return the matches.

  public function handleAutocomplete(Request $request) {
    // Getting the user input.
    $string = $request-&gt;query-&gt;get('q');
    // Getting the languages.
    $languages = \Drupal::languageManager()-&gt;getLanguages();
    // Getting the matches.
    $matches = preg_grep("/$string/i", $languages);
    // Returning the matches.
    return new JsonResponse($matches);
  }