如何在jquery ajax成功回调函数中传递上下文 [英] How to pass context in jquery ajax success callback function
本文介绍了如何在jquery ajax成功回调函数中传递上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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对象?
I'm not getting Box object inside exeSuccess method. How to pass Box object inside exeSuccess method?
推荐答案
使用 context
选项,如下所示:
Use the context
option, like this:
$.ajax({
context: this,
type: "post",
url: "some url",
success: this.exeSuccess,
error: this.exeError,
complete: this.exeComplete
});
上下文选项确定调用回调的上下文...因此它确定此
指的是该函数内部。
The context option determines what context the callback is called with...so it determines what this
refers to inside that function.
这篇关于如何在jquery ajax成功回调函数中传递上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文