【问题标题】:CORS issue while submitting data to google forms in angular以角度向谷歌表单提交数据时出现CORS问题
【发布时间】:2016-08-10 04:10:52
【问题描述】:

提交数据时: 错误信息:XMLHttpRequest 无法加载https://docs.google.com/forms/d/xxxxxxxxxxxxx/formResponse。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://localhost:8090' 不允许访问。响应的 HTTP 状态代码为 405。

    $scope.postDataToGoogle = function(){
    $http({
        method: 'POST',
        crossDomain: true,
        url: 'https://docs.google.com/forms/d/XXXXXXXXXXXXXXXXXXXXXXXX/formResponse',
        // dataType: "xml",
        data: tempData,
        }).success(function(data,status){
            //alert(data)
            console.log("Success");

        }).error(function(data,status) {
            console.log('Error:' + status);
        });

    }

【问题讨论】:

标签: javascript angularjs ajax cors


【解决方案1】:

我确实尝试过使用 angular 仍然无法解决它,但使用 jQuery 它对我有用。

$.ajax({
            url: 'https://docs.google.com/forms/d/xxxxxxxxx',
            data: tempData,
            type: "POST",
            dataType: "xml",
            statusCode: {
                0: function () {
                    alert('error');

                },
                200: function () {
                    alert('Thank you for your valuable feedback');

                }
            }
        })

【讨论】:

  • 我可以将数据类型发送为 json insted of xml。
【解决方案2】:

它与 jquery 或 Angular 无关,CORS 允许或禁止由后端服务器完成。 Google 可能不支持这个。(访问https://docs.google.com)

CORS(跨域资源共享)允许您更清晰地将前端与后端分开。

CORS 是一组从服务器发送的特殊响应头,告诉浏览器是否允许请求通过

访问控制允许来源:http://example.com。

Why does jQuery throw an error when I request external resources using an Appcache Manifest?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    相关资源
    最近更新 更多