Reputation: 81
a quick question, how can I put the content of a loaded file into a JavaScript variable?
function myfunc(){
$('.layer').load('content.txt');
}
I can access it with div class="layer", of course, but how can I also pass the result to a variable?
Thanks in advance!
Upvotes: 0
Views: 90
Reputation: 95518
I imagine this is what you want:
var content = "";
$('.layer').load("./content.txt", function(responseText, textStatus, XMLHttpRequest) {
content = responseText;
/* do stuff with content */
});
Upvotes: 2