jquery - Best way to keep textarea synced with server text file -


hi i'm making simple application users can type information text area , not have worry saving or losing it. i'm using jquery/javascript detect changes text area, using ajax send value php writing server. have basic "busy" lock prevent overlapping ajax. however, i'm finding unreliable. there better way this?

var busy = false;  function save () { if(busy === false) {     busy = true;     var content = $('#text').val();     var file = 'store.txt';     $.get("storecontent.php", { content_fromjq: content, file_fromjq: file})     .done(function(data) {      busy = false;     }); } }  $('#text').bind('input propertychange', function() { save(); }); 

php:

if (isset($_get['content_fromjq'])) {  $content = $_get['content_fromjq']; $file = $_get['file_fromjq'];   $html = new domdocument();   $html->loadhtmlfile($file);      $html->getelementbyid('content')->nodevalue = $content; $html->savehtmlfile($file);  } 

here : http://jsfiddle.net/z4rjq/

save listener when text change call function :

function checksave(){     cleartimeout(timer);     timer = settimeout(save, 5000); } 

this function clear timer , set other one.

in other word, there no save until user didnt press key 5 sec (adjustable).

that allow not send thousand of ajax save send 1 after finished typing something.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -