简体   繁体   English

如果我重新加载页面,AJAX表单提交来自浏览器的保存密码,没有“确认表单提交”请求

[英]AJAX Form submit with save password from browser and no “Confirm form submission” request if I reload the page

I'm doing a simple login form on my site. 我正在我的网站上做一个简单的登录表单。 Here is the situation: 情况如下:

  • If I do a pure Jquery AJAX form submission and then redirect (in the JS code), the browser doesn't offer to save the info (ie username and password). 如果我做一个纯Jquery AJAX表单提交然后重定向(在JS代码中),浏览器不提供保存信息(即用户名和密码)。
  • If I do a normal form submit, when I land on the next page and I do back or refresh, I get that very irritating and annoying "Confirm form submission". 如果我做一个正常的表格提交,当我登陆下一页然后我回来或刷新时,我会非常恼火和恼人的“确认表单提交”。

My question is, it possible to get the best of both worlds? 我的问题是,有可能两全其美吗? If yes, how? 如果有,怎么样?

To be clear, I want to do a form submit, preferably using AJAX so that if there is an error, I don't have to reload the page and just display the error, I want the browser to offer the possibility of saving the information and I don't want the "confirm form submission" on the page I redirect. 为了清楚起见,我想做一个表单提交,最好使用AJAX,这样如果有错误,我不必重新加载页面只显示错误,我希望浏览器提供保存信息的可能性我不想在我重定向的页面上“确认表单提交”。

I thought of adding a page in the middle, so submit to a blank page that just redirects to the page I want to go. 我想在中间添加一个页面,所以提交到一个空白页面,只是重定向到我想去的页面。 But once you are there, if you hit back, you are redirected to the same page, so you have click back 2 times. 但是一旦你在那里,如果你回击,你被重定向到同一页面,所以你再点击2次。 Is that how other people do it? 这是其他人怎么做的?

Thanks for your help. 谢谢你的帮助。

PS: I've seen all these posts... PS:我看过所有这些帖子......

PPS: Seems like the submit to iframe no longer works in modern browsers. PPS:似乎提交到iframe不再适用于现代浏览器。

For this to work, you need a well-formed HTML form element, with method and action, and a submit button as well, like this one: 要实现这一点,您需要一个结构良好的HTML表单元素,包含方法和操作,以及一个submit按钮,如下所示:

<form method="post" action="login.xxx" onsubmit="return validate();">
  <input type="text" id="username" />
  <input type="password" id="password" />

  <input type="submit" value="Send" />
</form>

After that, handle everything into the validate javascript method, preventing your form post (that will work on a non-javascript environment anyway) and using ajax instead: 之后,将所有内容处理为validate javascript方法,防止您的表单发布(无论如何都适用于非JavaScript环境)并使用ajax代替:

function validate() {
  // Ajax request using gathered form data, followed by a redirect to the logged-in page

  return false; // To prevent form submission
}

This way, your login info should be saved. 这样,您的登录信息应该保存。 For the "Confirm form submission" message, it will not appear since you'll do an javascript redirect if login info is okay. 对于“确认表单提交”消息,它将不会出现,因为如果登录信息可以,您将执行javascript重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM