title: Reading a file into a string in jQuery/JS
body: <p>The title is quite self-explanatory: I need to read a HTML file through jQuery and store its contents into a string variable.</p>
  
  <p>I tried using <code>.load</code> and <code>$.get</code>, but they wouldn't do what I needed.</p>
  
  <p>This is the code I've tried so far, based on the comments below, but they didn't populate my <code>template</code> variable at all:</p>
  
  <pre><code>var template = "";
  
  $.ajax({
      url: 'includes/twig/image_box.twig',
      type: 'get',
      success: function(html) {
          var twig = String(html);
          template.concat(twig);
      }
  });
  
  console.log(template);
  </code></pre>
  
  <p><strong>AND:</strong></p>
  
  <pre><code>var template = "";
  
  var fileUrl = "includes/twig/image_box.twig";
  jQuery.get(fileUrl).then(function(text, status, xhr){
      var html = String(text);
      template.concat(html);
  
      // console.log(html); // WORKS!
  });
  
  console.log(template); // Does not work
  </code></pre>
  
  <p>It's weird why this isn't working. Weird for me at least. This is how I'd populate a variable in PHP so I've carried the same logic to JS. Maybe there is an alternative way?</p>
  
  <p>P.S:V I've also tried all alternative ways, like concatenating with <code>+=</code> and assigning inside the callback function to template with <code>=</code>, but nothing worked.</p>
  
  <p>Thanks to the ones who are trying to help me!</p>