Ajax form submit and textbox value caching

446 Views Asked by At

I have a form (autocomplete='on') that contains a text input

<input type='text' name='code' />

When this form is submitted using $.ajaxSubmit() from jQuery Form Plugin, the value of the textbox is not getting cached by browsers.

Is it possible to somehow cache the values natively to a browser, so users can see their previous values when they start typing?

2

There are 2 best solutions below

1
zarpio On

At your first ajax call, make a cookie and store code into it, then in every other ajax calls, check if cookie(code) exist just print that value into your form field.

Here is a good tutorial for Javascript Cookies

0
Deval Khandelwal On

There is not a convenient way by which you can handle the process how the browsers handle autocomplete storage. You can use a workaround. For example: If you have a login form, you send the credentials using AJAX. If the credentials are incorrect, display an error message. Else login using AJAX and submit the form using Javascript. The form may be a fake one. Just handle the redirect in the submit page. That will store the credentials in autocomplete.