I have the following form which is placed on the page through AJAX (jQuery AJAX if that helps):
You can try "double-submit" technique.
In short: on first submit cancel it, but trigger it again after successful auth and do not cancel it.
More detailed:
You need to rewrite your form like this:
<form id="loginForm" onSubmit="return App.Auth.login();" method="POST" action="/back-redirector">
/back-redirector
just redirects back to the same page or to the main page. I am redirecting back to the same page.
And your App.Auth.login()
function must return false
when it is called first time, and return true
if the first call has resulted in successful login.
Like this:
letTheLoginFormDoTheSubmit = false;
// flag to show that login was successful
// and we need to trigger password save prompt.
login: function() {
if (letTheLoginFormDoTheSubmit) {
return true;
}
// Do the login
// Start ajax
ajax(login, password, function() {
// This function is called when AJAX has completed
if (loginIsGood) {
letTheLoginFormDoTheSubmit = true;
loginForm.submit(); // trigger submit again
});
return false;
}
So what happens?
Form is being submitted to the URL that just redirects browser back, and does not do any work.
Some caveats:
But in overall it is not a major change to the login process and should trigger password-save prompt in every browser.