I'm stuck on figuring out why function variables are empty after I receive result from another function.
Here I create a function (loader.js):
function Loader(){
this.url = null;
this.data = null;
this.successCallback = null;
}
Loader.prototype.LoadData = function(){
postAction(this.url, this.data, this.ResultCallback);
}
Loader.prototype.ResultCallback = function(result){
In this part I get this.successCallback as undefined same as the other variables in the function. It's like it's in the different scope.
if(this.successCallback){
this.successCallback(result)
};
};
After I initialize it in other js part (other.js):
loader = new Loader();
loader.url = url;
loader.data = data;
loader.successCallback = function(result) { .. };
loader.LoadData();
What I'm trying to do is use one ajax method for all calls, where it process server side logic and if it's successful, then it can proceed and return result.
postAction (global.js):
function postAction(url, data, successCallback){
$.ajax({
type: 'POST'
url: url,
data: data,
success: function(result){
if(successCallback){
successCallback(result);
};
});
};