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.