2015-10-22 122 views
0

我想通过AJAX请求将数据发送到Google表单。通过AJAX向Google表单发送数据

我已经设置了一个Google表单,当它从直接链接中使用时它工作正常。

然而,当我加载页面如下:

<!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] = "[email protected]"; 
     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> 

我得到以下错误:

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. 
+0

请检查这个https://wiki.base22.com/pages/viewpage.action?pageId=72942000 –

+0

这是我正在遵循的教程。我应该改变什么,特别是在我的代码示例中,以使其工作? – SeanPlusPlus

回答

0

错误是告诉你正在使用交叉起源Ajax请求。因此,您需要将atopype从xml更改为jsonp。这将解决您的表单提交问题。但是,你会得到以下错误:

拒绝从“https://docs.google.com/forms/d/key ...离子%201 &回调= jQuery111307080722744576633_1445478442168 & _ = 1445478442169”,因为它的MIME类型(文本/ html')不是可执行文件,并严格MIME类型执行脚本检查已启用。

此问题无法修复,因为呃更新Cross Domain JSONP XML Response