I'd like to load some content from an URL, to use it in my code. I tried closures and this:
function getStringFromURL(url) {
var getter = function() {
this.result = "undef";
this.func = function(response) {
this.result = response;
};
};
var x = new getter();
$.get(url, x.func);
return x.result; // the it returns "undef" and not the wanted response
}
Nothing worked at all. I'll never got the content, but if I call it with alert
like $.get("http://localhost:9000/x", function(response) {
alert(response)
});
it works -- but I'd like to save the response. I think theres a problem with the scope of the $.get
-method.
Whats wrong with this?