form 提交页面不刷新实现

// no redirect

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html, charset=utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta name="description" content="header and footer in checkout pages">
    <meta name="keywords" content="checkout, footer, header">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0" name="viewport">
    <title>页面form提交不刷新</title>
  </head>
  <body>
    <div>
      <iframe  name="J_iframe" width="100" height="100"> </iframe>
      <form action="https://test.com" method="post" target="J_iframe">
        <input type="text" name="name" value="lily" />
        <button>submit</button>
      </form>
    </div>
   	  </body>
</html>

解决被iframe时submit请求是iframe提交不是form提交问题
setTimeout(() => {
this.initForm.submit();
}, 10);

无刷新更换浏览器地址:
window.history.pushState(null, null, window.self.location); // 解决不能被iframe问题

doc: https://ctrlq.org/code/19233-submit-forms-with-javascript

原文地址:https://www.cnblogs.com/weilantiankong/p/11315211.html