0
我在JavaScript和jQuery中使用集成的ajax請求獲得以下代碼。 問:爲什麼可以調用內部函數success1()
,但不可能調用this.success2()
?針對此問題的任何解決方案建議JavaScript和jQuery:調用內部函數
function myfuntion() {
this.url = "www.example.com/ajax.php";
var success1 = function (data) {
alert("SUCCESS1");
}
this.success2 = function (data) {
alert("SUCCESS2");
}
this.send = function() {
$.ajax({
type: "POST",
url: this.url,
dataType: "html"
}).done(function (data) {
success1(data);
this.success2(data);
});
}
}
var test = new myfunction().send();
:
試試這個。 – 2013-04-06 11:13:56
您可能想看看http://stackoverflow.com/questions/3127429/javascript-this-keyword的接受答案,以獲得對JavaScript的「this」 – Exupery 2013-04-06 13:44:25