角度传递Json到谷歌电子表格getPost抛出e = undefined

时间:2016-02-23 10:45:03

标签: javascript angularjs json google-apps-script

Hy Guys,顺便提一句,我试图使用mhawksey / gist:1276293制作的appscript将带有Angular $ http功能的表单数据插入到Google电子表格中。

问题是什么:所有发布请求我最终都以电子表格中的未完成条目结束,因此getPost(e)函数中的e参数不会得到任何参数。我真的不知道断点在哪里,因为谷歌电子表格的获取响应会发送所有对象数据。

提前谢谢大家!

的index.php

<html ng-app="ngApp"> 
        <head>
        <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>


            <link rel="stylesheet" type="text/css" href="style.css">

        </head>

        <body ng-controller="controller">
         <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>


     <div id="test">
         <form name="form" ng-submit="submit()">
             <label>NAME</label>
            <input type="text" name="Name" ng-model="user.name">            
            {{user.name}}
             <label>SURNAME</label>
         <input type="text" name="Surname" ng-model="user.surname">            
            {{user.surname}}
         <button type="submit" class="btn">Submit</button>     
             </form>
                </div>


         <script src="app.js"></script>

        </body>

    </html>

app.js

var ngApp = angular.module('ngApp', []);
ngApp.controller('controller', function($scope, $http) {

$scope.user={};



$scope.submit=function() {

    $http({
          method  : 'POST',
          url     : "https://script.google.com/macros/s/AKfycbz2-BH3gDv_Wkjpg39vBwGvpUVbcBDNOHmtXfk9lRUoT04mRPw/exec",
          data    : $scope.user, //forms user object
          headers : {'Content-Type': 'application/x-www-form-urlencoded'} 
         })
     .then(function successCallback(response, statusText,data,config) {
    console.log("succees");
    console.log(statusText);
    console.log(data);
    console.log(config);
    console.log($scope.user.name);
        // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response, statusText,data,config) {

        console.log(statusText);
    console.log("failed");
        console.log(data);
    console.log(config);
    console.log($scope.user.name);// called asynchronously if an error occurs
    // or server returns response with an error status.
  });





};

});

1 个答案:

答案 0 :(得分:0)

您应该处理$ http。

的错误功能中的错误
$http({...}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

所以也许它可以传达一个错误,所以你没有得到填充的数据。