Using jQuery within a function to return text of a file
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/12475269/variable-doesnt-get-returned-from-ajax-function">Variable doesn’t get returned from AJAX function</a><br>
  <a href="http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call-from-a-function">How to return the response from an AJAX call from a function?</a>  </p>
</blockquote>



<p>I'm building a basic, local-only app. First time using jQuery - and I'll be bringing in a templating system once I settle on one (Leaning towards jsrender or mustache).</p>

<p>I'm trying to set things up so that a page can be loaded (Let's say home.html) and within it have it call upon a function that pulls data from a file and returns it.</p>

<p>I have this code</p>

<pre><code>function grabFile(name) {
    $.get(name+'.txt', function(data) {
        ...
    });
}
</code></pre>

<p>If I place a <code>Console.log(data)</code> in the middle, the console shows me the contents of the file. Success. Similar success if I use a <code>$('#output').html(data);</code> there in the middle.</p>

<p>But I'd like to set it up so that I can use a <code>&lt;script&gt;grabFile(name);&lt;/script&gt;</code> anywhere in an HTML file to call it. Using <code>return data;</code> in the middle, to the jQuery newbie, seemed like the solution... but that doesn't work.</p>

<p>Help?</p>
