0

I would like to send data to a Google Form via an AJAX request.

I've already setup a Google Form and it is working fine when I use it from a direct link.

However, when I load the below page:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Hello Google Forms</title>
  </head>
  <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js">
    </script>

    <script>

      // entry ids
      var entry_id_email = "entry.XXX";
      var entry_id_name  = "entry.XXX";

      // data to be sent
      var data = {};
      data[entry_id_email] = "foo@bar.com";
      data[entry_id_name]  = "Foo Bar";

      // form key
      var form_key = "XXX";

      // url
      var url = "https://docs.google.com/forms/d/" + form_key + "/formResponse";

      // ajax request
      $.ajax({
        url: url,
        data: data,
        type: "POST",
        dataType: "xml",
      });
    </script>
  </body>
</html>

I get the following error:

XMLHttpRequest cannot load https://docs.google.com/forms/d/XXX. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://myorigin' is therefore not allowed access.
SeanPlusPlus
  • 8,663
  • 18
  • 59
  • 84

1 Answers1

0

The error is telling that you are using cross origin ajax request. So you need to change the atatype from xml to jsonp. This will fix your form submission issue. But you will get following error:

Refused to execute script from 'https://docs.google.com/forms/d/key…ion%201&callback=jQuery111307080722744576633_1445478442168&_=1445478442169' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

This issue can not be fixed as er the udate Cross Domain JSONP XML Response .

Community
  • 1
  • 1
Dinesh Patra
  • 1,125
  • 12
  • 23