当ajax请求成功时,我会在同一个'class'中使用回调函数。这是代码
$.ajax({
type: 'get',
url: ajax_url,
success: this.callback
})
this.callback = function() {
// ERROR! this doesn't point to the right context!
this.run_some_process();
}
是否有任何内置的JavaScript结构可以让我获取或保存正确的上下文,而不必诉诸a custom delegate function?
答案 0 :(得分:2)
如果我理解你的问题。
var that = this;
$.ajax({
type: 'get',
url: ajax_url,
success: that.callback
})
that.callback = function() {
// ERROR! this doesn't point to the right context!
that.run_some_process();
}
答案 1 :(得分:0)
查看$.ajax's
'context' option。