如何在jquery ajax成功callback函数中传递上下文

var Box = function(){ this.parm = {name:"rajakvk",year:2010}; Box.prototype.jspCall = function() { $.ajax({ type: "post", url: "some url", success: this.exeSuccess, error: this.exeError, complete: this.exeComplete }); } this.exeSuccess = function(){ alert(this.parm.name); } } 

我没有得到在exeSuccess方法内的Box对象。 如何在exeSuccess方法内传递Box对象?

使用context选项 ,如下所示:

  $.ajax({ context: this, type: "post", url: "some url", success: this.exeSuccess, error: this.exeError, complete: this.exeComplete }); 

上下文选项确定什么上下文callback被调用…所以它确定this是什么引用该函数内。