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