title: How to Verify Google Recaptcha V3 Response with AJAX
body: <p>I have this function to execute Ajax POST request :</p>
  
  <pre><code>function ajaxPost(url, data, callback) {
      var req = new XMLHttpRequest();
      req.open("POST", url, true);
      req.addEventListener("load", function () {
          if (req.status &gt;= 200 &amp;&amp; req.status &lt; 400) {
              callback(req.responseText);
          } else {
              console.error(req.status + " " + req.statusText + " " + url);
          }
      });
      req.addEventListener("error", function () {
          console.error("Erreur réseau avec l'URL " + url);
      });
      req.send(data);
  }
  </code></pre>
  
  <p>But with this code, the captcah is never checked :</p>
  
  <pre><code>grecaptcha.ready(function() {
      grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
          var data = new FormData();
          data.set('g-recaptcha-response',token);
          ajaxPost("url", data, function(response){
              return response;
          });
      });
  });
  </code></pre>
  
  <p>The script execute <code>ajaxPost()</code> BEFORE <code>grecaptcha.execute()</code>.</p>
  
  <p>Thank you for your help !</p>