Ajax: autocomplete fields

For example, this situation. There is an ajax application in which a login form looks something like this:

<form>
 <input type="text" name="ajax-username">
 <input type="password" name="ajax-password">
 <input type="submit">
</form>


var form = document.querySelector( 'form' );

form.addEventListener( 'submit', function (e) {
 ajaxLogin(function () {
 form.innerHTML += '<br> success';
});
e.preventDefault();
}, false);


Ie, We intercept the form submit and instead perestrelyat page — send it ajax'ω, log ω and JS'generis new code.

But in this approach everything is fine except one — is "remembering" the entered data — login and password and next login instead of the browser framed have to enter them again.

If you just remove e.preventDefault(), the page after sabmita of the form will be reset.

Will advise if any solution to this problem?
October 8th 19 at 01:32
3 answers
October 8th 19 at 01:34
Solution
1. Make yourself a fake address that does nothing and returns 200 response
2. The form, define the fake web address and _target="iframe_name" (of course the frame should be)
2. Axboe before the data is sent to the correct address, do a real form submit.
3. Logintes Ajax, see how the browser asks whether to remember username/password
4.!!!
5. PROFIT!
By the way instead of e.preventDefault(); you can simply return falls. - aniya.Kertzmann65 commented on October 8th 19 at 01:37
false, as far as I remember, still do e.the stoppropagation() and, if there are other listeneri this event, it won't get to them. So just to return false might not be entirely correct. - saul.Trantow commented on October 8th 19 at 01:40
Thank you. Did start to remember and autopopulate email. But the password in this case — don't. =( - leila56 commented on October 8th 19 at 01:43
This is because of field name, insert first name the normal login and password, then it should all work. - aniya.Kertzmann65 commented on October 8th 19 at 01:46
Oh, and the truth. I tried to put email-password.
Thank you very much) - leila56 commented on October 8th 19 at 01:49
O. o how did I know? Three years have passed, it seems I'm slowly getting dumber :( - aniya.Kertzmann65 commented on October 8th 19 at 01:52
October 8th 19 at 01:36
Try to use history.pushState
I'm sorry, and you can read more like this goal is to use pushState? - aniya.Kertzmann65 commented on October 8th 19 at 01:39
If, after
form.innerHTML += '
success';
to write history.pushState();
the browser will offer to remember your password.
Tested only on Chrome - saul.Trantow commented on October 8th 19 at 01:42
October 8th 19 at 01:38
If I remember correctly, not only remembers the Google Chrome. As a solution you can redirect the form to a hidden frame, with the obligatory indication for the form's action attribute, different from the current page.

Find more questions by tags AJAXJavaScript