Save data offline before post

后端 未结 3 1685
臣服心动
臣服心动 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

提交回复
热议问题