Javascript 调用包含在同一类的方法中的jQuery AJAX中的方法
我一直在尝试从其中一个方法中的AJAX调用访问同一类的一些方法,但它不起作用。这里可能有什么问题?我得到这个错误Javascript 调用包含在同一类的方法中的jQuery AJAX中的方法,javascript,jquery,oop,javascript-objects,Javascript,Jquery,Oop,Javascript Objects,我一直在尝试从其中一个方法中的AJAX调用访问同一类的一些方法,但它不起作用。这里可能有什么问题?我得到这个错误未捕获类型错误:this.createTimeline不是一个函数请参见下面代码的注释 //sequenceRender is the class and below is one method sequenceRender.prototype.ajaxSequence = function(){ this.ajaxSequence = $.ajax('getSequence.
未捕获类型错误:this.createTimeline不是一个函数
请参见下面代码的注释
//sequenceRender is the class and below is one method
sequenceRender.prototype.ajaxSequence = function(){
this.ajaxSequence = $.ajax('getSequence.php', {
dataType: 'json',
timeout: 2000
});
this.ajaxSequence.done(function (data, status, jqXhr) {
console.log(data)
this.SEQUENCE=data // I cannot access properties
this.createTimeline() // or methods from same class
this.createWells() // from inside here
})
this.ajaxSequence.fail(function (jqXhr, textStatus, errorMessage) {
console.log(errorMessage)
})
}
当您试图在事件内部调用此函数时,此将具有不同的值 尝试添加以下更改,并让我知道这是否适用于您
sequenceRender.prototype.ajaxSequence = function() {
mainContext = this;
this.ajaxSequence = $.ajax('getSequence.php', {
dataType: 'json',
timeout: 2000
});
this.ajaxSequence.done(function (data, status, jqXhr) {
console.log(data)
mainContext.SEQUENCE=data
mainContext.createTimeline() // call the 'this' from here
mainContext.createWells()
})
this.ajaxSequence.fail(function (jqXhr, textStatus, errorMessage) {
console.log(errorMessage)
})
}
当您试图在事件内部调用此函数时,此将具有不同的值 尝试添加以下更改,并让我知道这是否适用于您
sequenceRender.prototype.ajaxSequence = function() {
mainContext = this;
this.ajaxSequence = $.ajax('getSequence.php', {
dataType: 'json',
timeout: 2000
});
this.ajaxSequence.done(function (data, status, jqXhr) {
console.log(data)
mainContext.SEQUENCE=data
mainContext.createTimeline() // call the 'this' from here
mainContext.createWells()
})
this.ajaxSequence.fail(function (jqXhr, textStatus, errorMessage) {
console.log(errorMessage)
})
}