有没有办法让JQuery ajax成功函数访问它所包含的对象?

我有这样的javascript:

function Cat() { this.meow = function() { // meow }; $.ajax( do AJAX call, success: this.meow(); ); } var TopCat = new Cat(); 

这不起作用,因为’this’在成功函数的上下文中没有意义。 有优雅的解决方案吗?

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

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