Mahesh Karthu Mahesh Karthu - 1 month ago 36
Ajax Question

CORS issue while submitting data to google forms in angular

While submitting the data :
Error Message : XMLHttpRequest cannot load https://docs.google.com/forms/d/xxxxxxxxxxxxx/formResponse. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8090' is therefore not allowed access. The response had HTTP status code 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);
});

}

Answer

I do have tried with angular still not able solve it, but with jQuery its works for me.

$.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');

                }
            }
        })