Possible Duplicate:
Variable doesn’t get returned from AJAX function
How to return the response from an AJAX call from a function?
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).
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.
I have this code
function grabFile(name) {
$.get(name+'.txt', function(data) {
...
});
}
If I place a Console.log(data)
in the middle, the console shows me the contents of the file. Success. Similar success if I use a $('#output').html(data);
there in the middle.
But I'd like to set it up so that I can use a <script>grabFile(name);</script>
anywhere in an HTML file to call it. Using return data;
in the middle, to the jQuery newbie, seemed like the solution... but that doesn't work.
Help?