Jahongir Rahmonov
Jahongir Rahmonov

Reputation: 13753

does reCaptcha work in localhost?

does it?

Everything is working fine, until I send the user response to the google server to verify. This is the code that sends the response:

$http({
    method: "get",
    url: "https://www.google.com/recaptcha/api/siteverify",
    params: {
       secret: 'my-secret-key',
       response: $scope.response
    }
}).success(function (response) {
    console.log(response);
}).error(function (errResponse) {
    console.log(errResponse)
});

Then, I am getting this:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.

Upvotes: 0

Views: 1177

Answers (1)

Alon Zilberman
Alon Zilberman

Reputation: 2155

Yes it works, but you can't send ajax/http requests to validate captcha from js. Yous should write your own backend function which will send this request.

Something like this:

  1. Getting response from captcha with js callback (as you already did)
  2. Send ajax request with captcha response to your own server
  3. From your server send request with response and secret key to https://www.google.com/recaptcha/api/siteverify
  4. Return response to your ajax function.

Upvotes: 1

Related Questions