我想从 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
}
根本没有任何效果。我永远不会得到内容,但如果我用它来调用它- 但我想保存响应alert
。我认为-method$.get("http://localhost:9000/x", function(response) {
alert(response)
});
的范围存在问题。$.get
这有什么问题?