title: Google reCaptcha response "Uncaught (in promise) null"
body: <p>I'm use reCaptcha v2 but in dev console response <code>Uncaught (in promise) null</code> in in any case (and moving the <code>.reset()</code> function) </p>
  
  <p>console:</p>
  
  <p><a href="https://i.stack.imgur.com/l24dC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/l24dC.png" alt="enter image description here"></a></p>
  
  <p>my code for recaptcha:</p>
  
  <pre><code>&lt;div class="text-xs-center" style="text-align: center; height:150px;"&gt;
      &lt;p style="color: black;"&gt; Complete the verification: &lt;/p&gt;
      &lt;div style="display: inline-block;" class="g-recaptcha" data-sitekey="xxxxxxxxxxx" data-callback="callback"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>my callback function:</p>
  
  <pre><code>function callback() {
      if (grecaptcha === undefined) {
          alert('Recaptcha non definito'); 
          return; 
      }
  
      var response = grecaptcha.getResponse();
      console.log(response);
  
      if (!response) {
          alert('Coud not get recaptcha response'); 
          return; 
      }
  
      $.ajax({
      'url' : 'validate-recaptcha.php',
      'type' : 'POST',
      'data' : {
          'response' : response   
      },
      'success' : function(data) {              
          alert('Data: '+data);
      },
      'error' : function(request,error)
      {
          alert("Request: "+JSON.stringify(request));
      }
      });
      grecaptcha.reset();
  }
  </code></pre>
  
  <p>and my <strong>validate-recaptcha.php</strong>:</p>
  
  <pre><code>&lt;?php
  //debug
  $fp = fopen('debug.txt', 'a');
  fwrite($fp, print_r($_POST, TRUE));
  fclose($fp);
  //enddebug
  
  if (empty($_POST['recaptcha'])) {
      exit('Please set recaptcha variable');
  }
  // validate recaptcha
  $response = $_POST['recaptcha'];
  $post = http_build_query(
      array (
          'response' =&gt; $response,
          'secret' =&gt; 'yoursecretkey',
          'remoteip' =&gt; $_SERVER['REMOTE_ADDR']
      )
  );
  $opts = array('http' =&gt; 
      array (
          'method' =&gt; 'POST',
          'header' =&gt; 'application/x-www-form-urlencoded',
          'content' =&gt; $post
      )
  );
  $context = stream_context_create($opts);
  $serverResponse = @file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);
  if (!$serverResponse) {
      exit('Failed to validate Recaptcha');
  }
  $result = json_decode($serverResponse);
  if (!$result -&gt; success) {
      exit('Invalid Recaptcha');
  }
  exit('Recaptcha Validated');
  </code></pre>
  
  <p>Searching on the internet, probably the problem is the <code>.reset()</code> function, but I do not understand the solution.</p>