Pretty new to javascript classes. Im having trouble accessing a method of my class from a thread (ajax post). Ive also tried MyClass.this.coolFunction but nothing works! i also cant assign
var THIS = this;
in the constructor as to access a class variable you must use "this.variable" but this from a thread does not reference the class
class MyClass(){
constructor(){
this.THIS = this;
}
coolFunction(){
}
fetchData(id){
$.post("ajax.php", {id: id},
function (response) {
THIS.coolFunction();//HELP! (cant access coolFunction :(
this.coolFunction();//does not work
}, " json");
}
}