Angular 将 Json 传递给 google 电子表格 getPost 抛出 e = undefined

Angular passing Json to google spreadsheet getPost throws e = undefined

本文关键字:抛出 getPost undefined 电子表格 google Json Angular      更新时间:2023-09-26

嘿伙计们,顺便说一下,第一个问题,我正在尝试使用mhawksey/gist:1276293制作的appscript将具有Angular $http功能的表单数据插入Google电子表格中。

问题是什么:我所做的所有 post 请求最终都会在我的电子表格中成为不可分割的条目,因此 getPost(e) 函数中的 e 参数没有任何参数。我真的不知道突破点在哪里,因为我的谷歌电子表格的获取响应会发送所有对象数据。

提前谢谢大家!

索引.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>

应用.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.
  });


};
});

您应该在$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.
  });
所以

也许它正在欺骗一个错误,所以你没有得到填充的数据。