Javascript 如何在jquery ajax成功回调函数中传递上下文
我没有在execsuccess方法中获取Box对象。如何在execsuccess方法中传递Box对象?使用,如下所示:Javascript 如何在jquery ajax成功回调函数中传递上下文,javascript,jquery,Javascript,Jquery,我没有在execsuccess方法中获取Box对象。如何在execsuccess方法中传递Box对象?使用,如下所示: var Box = function(){ this.parm = {name:"rajakvk",year:2010}; Box.prototype.jspCall = function() { $.ajax({ type: "post", url: "some url",
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);
}
}
context选项决定调用回调的上下文…因此它决定了该函数中该引用的内容。非常抱歉。目光短浅的jQuery文档。这里提到得很清楚,可能提到得很清楚,但还不清楚如何使用它。尼克的例子很有帮助。这篇文章更为详细:
$.ajax({
context: this,
type: "post",
url: "some url",
success: this.exeSuccess,
error: this.exeError,
complete: this.exeComplete
});