title: Redirect another page after successful form submission
body: <p>I need to redirect another page after successful form submission. I'm new in JavaScript. I need to know how to do the right way. Redirect to a other page after successful form submission through AJAX. first this code have a form submission after redirect to another page.</p>
  <p>I'm Programming with php/wordpress.</p>
  <p>php/html code:</p>
  <pre><code>&lt;form id=&quot;alecaddd-testimonial-form&quot; action=&quot;#&quot; method=&quot;post&quot; data-url=&quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;&gt;
  
    &lt;div class=&quot;field-container&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;field-input&quot; placeholder=&quot;Adult&quot; id=&quot;name&quot; name=&quot;name&quot; required&gt;
      &lt;small class=&quot;field-msg error&quot; data-error=&quot;invalidName&quot;&gt;Your Name is Required&lt;/small&gt;
    &lt;/div&gt;
  
    &lt;div class=&quot;field-container&quot;&gt;
      &lt;input type=&quot;text&quot; class=&quot;field-input&quot; placeholder=&quot;infant&quot; id=&quot;infant&quot; name=&quot;infant&quot; required&gt;
      &lt;small class=&quot;field-msg error&quot; data-error=&quot;invalidName&quot;&gt;Your Name is Required&lt;/small&gt;
    &lt;/div&gt;
  
  
    &lt;div class=&quot;field-container&quot;&gt;
      &lt;input type=&quot;email&quot; class=&quot;field-input&quot; placeholder=&quot;Child&quot; id=&quot;email&quot; name=&quot;email&quot; required&gt;
      &lt;small class=&quot;field-msg error&quot; data-error=&quot;invalidEmail&quot;&gt;The Email address is not valid&lt;/small&gt;
    &lt;/div&gt;
  
    &lt;div class=&quot;field-container&quot;&gt;
      &lt;input type=&quot;date&quot; class=&quot;field-input&quot; placeholder=&quot;date&quot; id=&quot;date&quot; name=&quot;date&quot; required&gt;
      &lt;small class=&quot;field-msg error&quot; data-error=&quot;invalidEmail&quot;&gt;The Email address is not valid&lt;/small&gt;
    &lt;/div&gt;
  
  
  
    &lt;div class=&quot;field-container&quot;&gt;
      &lt;textarea name=&quot;message&quot; id=&quot;message&quot; class=&quot;field-input&quot; placeholder=&quot;Your Message&quot; required&gt;&lt;/textarea&gt;
      &lt;small class=&quot;field-msg error&quot; data-error=&quot;invalidMessage&quot;&gt;A Message is Required&lt;/small&gt;
    &lt;/div&gt;
    
    &lt;div class=&quot;field-container&quot;&gt;
      &lt;div&gt;
        &lt;a href=&quot;order.php?id=102&quot; class=&quot;btn btn-success&quot;&gt;
              &lt;button type=&quot;stubmit&quot; class=&quot;btn btn-default btn-lg btn-sunset-form&quot;&gt;BOOK NOW&lt;/button&gt;
          &lt;/div&gt;
          &lt;/a&gt;
      &lt;small class=&quot;field-msg js-form-submission&quot;&gt;Submission in process, please wait&amp;hellip;&lt;/small&gt;
      &lt;small class=&quot;field-msg success js-form-success&quot;&gt;Message Successfully submitted, thank you!&lt;/small&gt;
      &lt;small class=&quot;field-msg error js-form-error&quot;&gt;There was a problem with the Contact Form, please try again!&lt;/small&gt;
    &lt;/div&gt;
  
    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;submit_testimonial&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;nonce&quot; value=&quot;&lt;?php echo wp_create_nonce(&quot;testimonial-nonce&quot;) ?&gt;&quot;&gt;
  
  &lt;/form&gt;
  </code></pre>
  <p>Javascript:-</p>
  <pre><code> ! function o(n, i, u) {
  function c(r, e) {
      if (!i[r]) {
          if (!n[r]) {
              var t = &quot;function&quot; == typeof require &amp;&amp; require;
              if (!e &amp;&amp; t) return t(r, !0);
              if (l) return l(r, !0);
              var s = new Error(&quot;Cannot find module '&quot; + r + &quot;'&quot;);
              throw s.code = &quot;MODULE_NOT_FOUND&quot;, s
          }
          var a = i[r] = {
              exports: {}
          };
          n[r][0].call(a.exports, function(e) {
              return c(n[r][1][e] || e)
          }, a, a.exports, o, n, i, u)
      }
      return i[r].exports
  }
  for (var l = &quot;function&quot; == typeof require &amp;&amp; require, e = 0; e &lt; u.length; e++) c(u[e]);
  return c }({
  1: [function(e, r, t) {
      &quot;use strict&quot;;
  
      function o() {
          document.querySelectorAll(&quot;.field-msg&quot;).forEach(function(e) {
              return e.classList.remove(&quot;show&quot;)
          })
      }
      document.addEventListener(&quot;DOMContentLoaded&quot;, function(e) {
          var a = document.getElementById(&quot;alecaddd-testimonial-form&quot;);
          a.addEventListener(&quot;submit&quot;, function(e) {
              e.preventDefault(), o();
              var r = {
                  name: a.querySelector('[name=&quot;name&quot;]').value,
                  email: a.querySelector('[name=&quot;email&quot;]').value,
                  message: a.querySelector('[name=&quot;message&quot;]').value,
                  nonce: a.querySelector('[name=&quot;nonce&quot;]').value
              };
              if (r.name)
  
                  
                  if (/^(([^&lt;&gt;()\[\]\\.,;:\s@&quot;]+(\.[^&lt;&gt;()\[\]\\.,;:\s@&quot;]+)*)|(&quot;.+&quot;))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(r.email).toLowerCase()))
                      if (r.message) {
                          var t = a.dataset.url,
                              s = new URLSearchParams(new FormData(a));
                          a.querySelector(&quot;.js-form-submission&quot;).classList.add(&quot;show&quot;), fetch(t, {
                              method: &quot;POST&quot;,
                              body: s
                          }).then(function(e) {
                              return e.json()
                          }).then(function(e) {
                              window.location.href = 'https://www.google.com';
                          }).catch(function(e) {
                              o(), a.querySelector(&quot;.js-form-error&quot;).classList.add(&quot;show&quot;)
                          }).then(function(e) {
                              o(), 0 !== e &amp;&amp; &quot;error&quot; !== e.status ? (a.querySelector(&quot;.js-form-success&quot;).classList.add(&quot;show&quot;), a.reset()) : a.querySelector(&quot;.js-form-error&quot;).classList.add(&quot;show&quot;)   
                          })
                         
                      } else a.querySelector('[data-error=&quot;invalidMessage&quot;]').classList.add(&quot;show&quot;);
              else a.querySelector('[data-error=&quot;invalidEmail&quot;]').classList.add(&quot;show&quot;);
              else a.querySelector('[data-error=&quot;invalidName&quot;]').classList.add(&quot;show&quot;)
          })
      })
  }, {}] }, {}, [1]); //# sourceMappingURL=form.js.map
  </code></pre>
  <p>Any help, as always, is greatly appreciated.</p>