I know the there is a lot of questions on this topic, but I really couldn't find anything what fits to my case. I defined this function in javascript:
self.ajax = function(uri, method, data) {
var request = {
url: uri,
type: method,
contentType: "application/json",
accepts: "application/json",
cache: false,
dataType: 'json',
data: JSON.stringify(data),
error: function(jqXHR) {
console.log("ajax error" + jqXHR.status);
}
};
return $.ajax(request);
}
And I call this function later like that:
self.ajax(self.tasksGetUri, 'POST', self.jsonRequest).done(function(data) {
for (var i = 0; i < data.tasks.length; i++) {
self.tasks.push({
user_id: ko.observable(data.tasks[i].user_id),
task_id: ko.observable(data.tasks[i].task_id),
done: ko.observable(data.tasks[i].done)
});
}
$(document).ready(function() {
for (var i = 0; i < self.tasks().length; i++) {
task = $("#" + self.tasks()[i].task_id());
if (task.length) {
task.slideUp(400);
task.parent().find(".unFinishedTask").hide();
task.parent().addClass("finished");
task.parent().find(".showTask").show();
}
}
});
});
Well, I want this calling of the function to be performed periodically together with return 'done()' function. I know the there is function setInterval(), but I don't know if it fits in my case. Can somebody recommend me some other solution ?
Thanks in advance for any help.