"Access-Control-Allow-Origin" error in recaptcha call

I am embedding recaptcha in my angularJS registration form. But I get an error because ** "XMLHttpRequest cannot load https://www.google.com/recaptcha/api/verify . The requested resource does not have the header" Access-Control-Allow-Origin ".

I used https://github.com/VividCortex/angular-recaptcha for recaptcha.

My code is as follows.

<head>
    <script>
            var app = angular.module('testApp', ['vcRecaptcha']);

            app.controller('testCtrl', function ($scope, vcRecaptchaService) {
                console.log("this is your app controller");

                $scope.model = {
                    key: ' -- public key--'
                };

                $scope.submit = function () {
                    var valid;
                    console.log('Submit button');
                    var challenge =  $('#recaptcha_challenge_field').val();
                    var response =  $('#recaptcha_response_field').val();
                    console.log('challenge' + challenge );
                    $.ajax({
                    url: "https://www.google.com/recaptcha/api/verify",
                    type: 'POST',       
                    data: {
                        privatekey  : '--my private key --',
                        remoteip : '--my ip--',
                        challenge : challenge,
                        response : response,
                    },
                    success: function(data){
                        console.log(" success " + data);
                    },
                    error:function(){
                           console.log(" error occured ");
                    }
                      }); 
                   }
                };
            });
        </script>

    </head>
    <body>
    <div class="container" ng-app="testApp" ng-controller="testCtrl">

        <h1>VividCortex reCaptcha Directive Example</h1>


        <form>
            <div
                vc-recaptcha
                tabindex="3"
                theme="clean"
                key="model.key"
            ></div>

            <!-- Call a method in the scope of your controller to handle data submit -->
            <button class="btn" ng-click="submit()">Submit</button>
        </form>

    </div>
    </body>
+1
source share

All Articles