0

I have a following script on my aspx page that i am trying to do a post method to pass data to a url as follows:

        <script>
         $.ajax({
             type:"POST",
              url: "https://www.google.com/recaptcha/api/siteverify",
              crossDomain: true,
              data: {"secret" : "0000000", "response" : response, "remoteip":"localhost"},
              contentType: "application/json; charset=utf-8",
              success: function (data) {
               console.log(data + "test");
              }
             });
          </script>

when it hits the URL mentioned above i get the following error Access to XMLHttpRequest at 'https://www.google.com/recaptcha/api/siteverify' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

how do i get this to work?

marry
  • 153
  • 2
  • 3
  • 15
  • 1
    enable CORS in server side – ArunKumar M N Jun 21 '19 at 09:18
  • You can't do this client-side. Even if the same origin policy didn't prevent you, putting the mechanism to ensure that the client is controlled by a human *in the hands of the client* makes it trivial to bypass. – Quentin Jun 21 '19 at 09:21
  • 1
    @ArunKumarMN — That would require them to be Google, which seems unlikely. – Quentin Jun 21 '19 at 09:21
  • Read more about CORS before working on cross-domain requests. http://www.ajax-cross-origin.com/how.html Make sure your server is enabled to handle cross domain requests – Bhagirath Jun 21 '19 at 09:23

0 Answers0