AJAX自动保存功能

人气:1,072 发布:2022-09-11 标签: javascript ajax synchronize

问题描述

什么是最好的JavaScript库,或插件或扩展到库中,已经实现自动保存功能?

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

具体需要的是能够拯救数据网格。想想Gmail和谷歌文档自动保存。

The specific need is to be able to 'save' a data grid. Think gmail and Google Documents' autosave.

我不想重新发明轮子,如果它已经被发明了。我在寻找神奇的自动保存()函数中现有的实现。

I don't want to reinvent the wheel if its already been invented. I'm looking for an existing implementation of the magical autoSave() function.

自动保存:推到服务器code,它保存到永久存储,通常一个DB。服务器code框架是对这个问题的范围。

Auto-Saving:pushing to server code that saves to persistent storage, usually a DB. The server code framework is outside the scope of this question.

请注意,我不是在寻找一个Ajax库,但是库/框架水平:交互形式本身

Note that I'm not looking for an Ajax library, but a library/framework a level higher: interacts with the form itself.

daemach出台实施jQuery的@顶部http://daemach.blogspot.de/2007/03/autosave-jquery-plugin.html [脚本宿主下来。我不相信它符合轻便,精心设计的标准虽然。

daemach introduced an implementation on top of jQuery @ http://daemach.blogspot.de/2007/03/autosave-jquery-plugin.html [script host down]. I'm not convinced it meets the lightweight and well engineered criteria though.

标准

稳定,重量轻,精心设计的 节约的onChange和/或的onblur 节约毫秒不再那么频繁的给定数量 在处理多个更新发生在同一时间 在不保存,如果没有发生变化,因为上次保存 保存到每个输入级不同的URL stable, lightweight, well engineered saves onChange and/or onBlur saves no more frequently then a given number of milliseconds handles multiple updates happening at the same time doesn't save if no change has occurred since last save saves to different urls per input class

推荐答案

自动转存应该是pretty的实现简单,你可以使用像jQuery或MooTools的重要框架之一。所有你需要做的是使用window.setTimeout(),一旦用户编辑东西应该被自动保存,并有超时调用JavaScript框架标准的AJAX的东西。

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.

例如(使用jQuery):

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
    }
}

544