AJAX Autosave functionality

前端 未结 8 1624
旧巷少年郎
旧巷少年郎 2020-12-07 09:54

What\'s the best javascript library, or plugin or extension to a library, that has implemented autosaving functionality?

The specific need is to be able to \'save\'

相关标签:
8条回答
  • 2020-12-07 10:30

    synchronize is a jquery plugin that adds functionality to your html page to periodically automatically send user input back to the server. (source code)

    JavaScript and HTML sample:

    <script>
      $("input").synchronize();
    </script>
    
    <input type="text" value="initial_value" 
           class="{url:'/entity.cfc?method=updateDescription',data:{ID1:'1',ID2:'2'}}" />
    

    resulting ajax request after the default delay of 1s:

    http://localhost/entity.cfc?method=updateDescription&value=update_value&preVal=initial_value&ID1=1&ID2=2
    
    0 讨论(0)
  • 2020-12-07 10:32

    Autosave should be pretty simple to implement, and you could use one of the major frameworks like jquery or mootools. All you need to do is use window.setTimeout() once your user edits something that should be autosaved, and have that timeout call the javascript frameworks standard AJAX stuff.

    For example (with jquery):

    var autosaveOn = false;
    function myAutosavedTextbox_onTextChanged()
    {
        if (!autosaveOn)
        {
            autosaveOn = true;
    
            $('#myAutosavedTextbox').everyTime("300000", function(){
                 $.ajax({
                     type: "POST",
                     url: "autosavecallbackurl",
                     data: "id=1",
                     success: function(msg) {
                         $('#autosavenotify').text(msg);
                     }
                 });
            }); //closing tag
        }
    }
    
    0 讨论(0)
提交回复
热议问题