Skip to content

Instantly share code, notes, and snippets.

@slav123
Created September 8, 2021 14:08
Show Gist options
  • Save slav123/73d18b9e43e7319340e7f3e96ba2719c to your computer and use it in GitHub Desktop.
Save slav123/73d18b9e43e7319340e7f3e96ba2719c to your computer and use it in GitHub Desktop.
simple javascript autosave
var timeoutId;
$(document).on('keypress', '#overview', function () {
if (timeoutId) clearTimeout(timeoutId);
let brief = $(this).val()
let steps_id = $(this).data('id')
timeoutId = setTimeout(function () {
$.ajax({
type: "POST",
url: base_url + 'client/save_brief',
dataType: "json",
data: {body: brief, id: steps_id},
success: function (data) {
console.log('saved');
},
error: universalErrorHandler
});
}, 750);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment