小编Nic*_*olo的帖子

从网站表单写入谷歌文档时遇到 CORS 错误

我的网站上有一个表单,应该将文本字段“电子邮件”写入谷歌电子表格。提交表单时,它会调用一个函数,该函数将 jquery ~ v 1.4 ajax POST 发送到谷歌文档。(我已经测试了谷歌表单并且它有效)

我遇到了 CORS 错误。

跨域请求被阻止:同源策略不允许在https://docs.google.com/forms/ **********************读取远程资源 **************************** /formResponse. 这可以通过将资源移动到同一域或启用 CORS 来解决。

  • 我显然无法将 google 文档移动到同一个域。
  • 我没有服务器的配置控制。
  • 我不想进行任何会影响站点上许多其他 ajax 和 $httpProvider 使用的全局 angularjs 更改。
  • 我不想将谷歌表单作为 iframe 嵌入网站中。

我的阿贾克斯是

$scope.storeEmail = function() {
var email = $scope.fA.email;
$.ajax({type: "POST",
        async: true,
        url: 'https://docs.google.com/forms/***************************/formResponse',
        data: { field_key : email, submit : "Submit"},
        success: function(resp) {
        // give success feedback and redirect page
        }
        error: function(xhr, statusText, error){
          console.log(xhr);
        }        
};
Run Code Online (Sandbox Code Playgroud)

我试过 向 ajax 请求添加凭据和标头

withCredentials: …
Run Code Online (Sandbox Code Playgroud)

ajax google-docs google-sheets cors angularjs

5
推荐指数
1
解决办法
2323
查看次数

标签 统计

ajax ×1

angularjs ×1

cors ×1

google-docs ×1

google-sheets ×1