I have javascript like this:
function Cat() {
this.meow = function() { // meow };
$.ajax( do AJAX call, success: this.meow(); );
}
var TopCat = new Cat();
This does not work because ‘this’ makes no sense in the context of the success function. Is there an elegant solution?
You’re looking for the
contextparameter to theajaxmethod.It allows you to set the context in which all callbacks will be called.