title: How to trigger a JS function in HTML with multiple context.res from REST API
body: <p>I am using the following code in an HTML webpage:</p>
  
  <pre><code>    var request = new XMLHttpRequest();
      var url= "my azure httptrigger";
      request.open('GET', url, true);
      request.onload = function () {
  
        // Begin accessing JSON data here
        var data = this.response;
  
        if (request.status &gt;= 200 &amp;&amp; request.status &lt; 400) {
          document.getElementById('results').innerHTML  = data;
      function2();
        } else {
          console.log('error');
        }
      }
      request.send();
  </code></pre>
  
  <p>In my API (httptrigger in Azure Functions) I use:</p>
  
  <pre><code>context.res = {
      body: bodyStuff,
      headers: {
          'Content-Type': 'text/html; charset=utf-8'
      }
  }
  </code></pre>
  
  <p>to determine the data to send back from the API. This means when I end the Azure function - the data sent in the <code>body</code> in <code>context.res</code> is sent to my webpage and displayed.</p>
  
  <p>This works fine and as planned. However, what I am looking for is the ability to send data back in two parts.</p>
  
  <p>(I attempted to define <code>context.res</code> twice but this didn't work as the second definition overrode the first)</p>
  
  <p>Is there an effective way to do this?</p>
  
  <p>In essence, a user hits my API and I want to send partial data to the webpage from the API halfway through the function, and then more data at the end. This is to make the user experience on the webpage quicker than waiting for all the data to load/function to finish.</p>