Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 调用包含在同一类的方法中的jQuery AJAX中的方法_Javascript_Jquery_Oop_Javascript Objects - Fatal编程技术网

Javascript 调用包含在同一类的方法中的jQuery 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.

我一直在尝试从其中一个方法中的AJAX调用访问同一类的一些方法,但它不起作用。这里可能有什么问题?我得到这个错误
未捕获类型错误: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)
  })
}