Auto saving JAVASCRIPT data via AJAX to database -
apologies if particular question has been solved before, have looked everywhere seems , can't quite answer i'm looking for! no expert , can imagine solution embarrassingly easy.
my problem this: have php , javascript code working on html based website, linked database (reading data in , writing data out via save function called once @ end of script). need javascript code automatically save/update db via ajax request, without need keep running page. data being saved here needs read various other pages , relied upon give correct results elsewhere! (so solution have user keep page open in background - suggestions separate issue welcome!)
anyway, @ moment have:
function sessionsave () { var newdata = kpica.getdata().concat(kpiha.getdata(),kpistocks.getdata(),kpicv.getdata(),kpipd.getdata()); $.ajax({ url: 'savemain.php', type: 'post', data: {'kpi': newdata}, success: function () { }, error: function () { $console.text('data save error'); } }); } sessionsave(); i have seen autosave scripts , addition of timers etc. complete noob, appreciated,
thanks guys!
basically it's timers or intervals. example:
window.setinterval(sessionsave, number_of_seconds * 1000) // number_of_seconds is, obviously, number of seconds repeat function @
Comments
Post a Comment