This is a simple AJAX call I have created for autosaving an edition in a page. When the timer is triggered it performs an AJAX call for saving the page, disables the save button and shows a message that indicates that the autosave action was performed. Any user event on page enables the save button again.
$.ajax({
"dataType": "JSON",
"type": "POST",
"url": "/autosave",
"success": function(result) {
var $messagePanel = $("#autoSaveMsg");
$messagePanel.show();
$messagePanel.css("top",$(window).scrollTop()+ 200 + "px");
setTimeout(function() {
$messagePanel.fadeOut("slow");
}, 2000);
}
});
},
userEvent: function() {
$("#post_job #btnSaveAccordion").removeAttr("disabled");
},
init: function(options){
$(document).bind("click dblclick mousedown mouseenter mouseleave", Behaviour.AutoSaveTimer.userEvent);
window.setInterval(Behaviour.AutoSaveTimer.autoSave, options.period);
}
No hay comentarios:
Publicar un comentario