2011-03-21 41 views

回答

7

您正在寻找ajax方法的context参数。
它允许您设置所有回调将被调用的上下文。

function Cat() { 
    this.meow = function() { // meow }; 
    $.ajax({ 
     context: this, 
     success: function() { this.meow(); } 
    });  
} 
+0

很好,谢谢! – NibblyPig 2011-03-21 14:00:41

+0

谢谢。尽管我需要做'success:function(){this.context.meow();}' – Greg 2011-05-19 11:08:44

+1

注意:如果设置'context:this',你也可以写'success:this.meow' - 不需要额外的函数包装器。 – Alnitak 2013-10-09 14:34:38

相关问题