I want to assign value to a class instance variable from within ajax success functions, code will explain better what I mean.
var SomeClass = function() {
this.someMethod = function() {
$.ajax({
method: 'GET',
url: 'http://example.com',
success: function(resp) {
var js = JSON.parse(resp);
// I want to assign js object to SomeClass.response instance variable
};
});
};
};
If I try this.response, it obviously doesn't work. If I assign this to some variable before I make ajax call, It doesn't work either. I mean this:
var SomeClass = function() {
this.someMethod = function() {
// Asign this to self
var self = this;
$.ajax({
method: 'GET',
url: 'http://example.com',
success: function(resp) {
var js = JSON.parse(resp);
// I want to assign js object to SomeClass.response instance variable
self.response = js; // However it doesn't work
};
});
};
};
I'll appreciate your help!!!
responselater.SomeClass. Then you probably dosoveVariable.someMethod(). And what next?