How to display data without html on ajax call?
I have done this in a custom controller before. You don't want to return a render array, because Drupal will take the default action.

Instead, you want to render it to HTML (string) and return that back. Something like this:

$rendered = $this-&gt;renderer-&gt;renderRoot($build_array);
$response = new Response();
$response-&gt;setContent($rendered);
return $response;


As far as the Javascript, here is a generic example using fetch (in a twig file):

  &lt;script&gt;
    fetch("{{ auth_url }}", { credentials: "include" })
      .then(
        function(response) {
          if (response.status !== 200) {
            console.log('Looks like there was a problem. Status Code: ' + response.status);
            return;
          }

          response.text().then(function(data) {
            document.getElementById("authorize-banner").innerHTML = data;
          });
        }
      )
      .catch(function(err) {
        console.log('Fetch Error :-S', err);
      });
  &lt;/script&gt;

  &lt;div id="authorize-banner"&gt;&lt;/div&gt;


You also likely don't want to cache the render array either. You can also greatly simplify the API fetch code by using Guzzle (Client) instead of curl.