我想从一个 URL 上加载一些内容, 并将其用在我的代码中。 我尝试关闭关闭, 并且这样:
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.
这有什么错?