AJAX Autosave functionality

前端 未结 8 1658
旧巷少年郎
旧巷少年郎 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:20

    I know that this question is old, but I would like to include a code that I like the most. I found it here: http://codetunnel.io/how-to-implement-autosave-in-your-web-app/

    Here is the code:

    var $status = $('#status'),
        $commentBox = $('#commentBox'),
        timeoutId;
    
    $commentBox.keypress(function () { // or keyup to detect backspaces
        $status.attr('class', 'pending').text('changes pending');
    
        // If a timer was already started, clear it.
        if (timeoutId) clearTimeout(timeoutId);
    
        // Set timer that will save comment when it fires.
        timeoutId = setTimeout(function () {
            // Make ajax call to save data.
            $status.attr('class', 'saved').text('changes saved');
        }, 750);
    });
    

    It saves after the user stops writing for more than 750 milliseconds.

    It also has a status letting the user know that the changes have been saved or not

提交回复
热议问题