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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM