Save data offline before post

后端 未结 3 1649
臣服心动
臣服心动 2021-01-21 15:26

i want to save the post data to user pc before posting just incase of bad internet connection where it happens a lot in my area.

most of the time users write article , a

相关标签:
3条回答
  • 2021-01-21 15:37

    CODE :

        function saveEditsBeforeSend(inputIdThatyouWantToGrabState){
    
            var contentOfInput = $(inputIdThatyouWantToGrabState).val();
    
            $.cookie("userInputContentOf"+$(inputIdThatyouWantToGrabState).attr("id"), contentOfInput); 
    
    }
    

    Add a event listerner and call it before send

        $("#yourFormId").on("submit", function(e){
            e.preventDefault();
            var form = $(this);         
            saveEditsBeforeSend(form.find("#inputIdThatyouWantToGrabState"));
            form.trigger("submit");     
    });
    

    This code will store content of input in cookies that you can use later when the connection will be ok. (Note that this content will be lost if the user lost his session) Thats an idea you can perfectionize it

    0 讨论(0)
  • 2021-01-21 15:46

    Add a submit listener to your form, prior submitting save all the form input values in the browser's local storage. In older browsers (IE) you can "polyfill" this non-existent functionality.

    Have a look at this list of browser storage polyfills.

    0 讨论(0)
  • 2021-01-21 15:54

    HTML5 includes a spec called LocalStorage, which allows you to store some information in the clients browser like cookies has in the past. This method is great because cookies are tiny in size and very insecure.

    There is a nice article about it here: http://diveintohtml5.info/storage.html

    0 讨论(0)
提交回复
热议问题