I've a set interval function like this -
setInterval(function(){
var postData = {'some json data'};
var successCallback = function(data) {
console.log(data);
}
var errorCallback = function(data) {
console.log(data);
}
RestClient.invokeRemoteService(postData, this.successCallback, this.errorCallback);
}, 10000);
And Here is my invokeRemoteService()
method at of RestClient
(at another file) -
RestClient = window.RestClient || {};
(function (w, rs) {
rs.invokeRemoteService = function ( postData, successCallBack, errorCallBack){ //label-1, successCallback and errorCallback are undefined
$.ajax({
url : '/some/url/',
dataType : "json",
data :{
cmd: ko.toJSON(postData)
},
type : "post",
async : true,
success : function(data) { //label-2, get data ok
if (typeof successCallBack === "function") { //label-3, successCallBack is undefined
successCallBack(data); //label-4
}
},
error : function() {
if (typeof errorCallBack === "function") {
errorCallBack(); //label-5
}
}
});
};
})(window, RestClient);
But when I call RestClient.invokeRemoteService()
method from setInterval()
method I always get 'undefined' for successCallback
and errorCallback
at label-1
, label-3
and label-5
.
Though the service call done perfectly and I get correct data at label-2. The
RestClient.invokeRemoteService()work fine for other. But when I call it from
setInterval()` its not working. Please help.