I am working on autosaving a form using jQuery. This form will keep saving data every 1 min. However, I don't want to spam the database if the user has that browser open for one day. So I want to kill the autosave option if there is no change or if the browser has been open for 30 min.
Anyway I can kill this autosave function?
$("form input").on("input propertychange change", function() {
var start = $.now();
setTimeout(autoSaveForm(start), 10000);
});
function autoSaveForm(start) {
var uuid = $("#uuid").html();
$.ajax({
type: "POST",
url: "trailers/" + uuid + "/save-draft",
data: $("form").serialize(),
success: function() {
}
});
if ($.now() - start <= 600000) {
setTimeout(autoSaveForm(start), 60000);
}
else {
return;
}
}