我想創建一個仍然保留訪問當前對象的ajax請求。有誰知道這是否可能?的想什麼,我做Javascript OOP - jQuery在ajax請求中調用「this」
例子:
function mobile_as(as_object, inputID) {
this.object = 'something';
if (as_object) this.object = as_object;
this.inputID = inputID;
// Get results for later usage.
this.get_results = function(value) {
this.request = $.getJSON("URL", { as: this.object }, function (data) {
// Scope of "this" is lost since this function is triggered later on.
if (data['status'] == "OK") {
alert(this.inputID);
}
});
}
}
}
僅供參考JavaScript並不是OOP。 – jrummell 2012-03-23 19:58:30
@ jrummell這是主觀的不是嗎? http://stackoverflow.com/questions/107464/is-javascript-object-oriented – teynon 2012-03-23 20:07:06
我認爲不是,但你可以自由地不同意。 – jrummell 2012-03-23 20:09:22