PHP 页面打印 null 通过 angularjs 传递数据

php page prints null passing data through angularjs

提问人:Gregory Carmo 提问时间:11/10/2023 更新时间:11/10/2023 访问量:28

问:

早上好!我正在尝试将数组从 angularjs 传递给 php。我需要在php页面上打印数据,而不是将其返回给angular js中的函数。在 php 页面上,它打印 null,但在 js 函数中,它正确地接收了返回值。

页面 html,列出表格中的数据

<tr dir-paginate="rem in remessa | itemsPerPage:exibirQuant">
                    <td><a ng-click="buscarFunc(rem)" ng-bind="rem.nome"></a></td>
                    <!--<td><input type="checkbox" ng-model="rem.selected" value="{{rem.nome}}" class="form-check-input"></td>-->
                    <td><input type="checkbox" name="{{rem.nome}}" value="{{rem.nome}}" ng-model="rem.selected"></td>
                    <td>{{rem.valorBruto}}</td>
                    <td></td>
                    <td>{{rem.desconto}}</td>
                    <td></td>
                    <td>{{rem.valorLiquido}}</td>           
                </tr>

<button class="btn btn-danger" ng-click="salvar()">Salvar</button>
/* lists employees coming from the bank in a table */
$http.post('assets/php/remessa_rj.php', {'tipo':'listar', 'data_ini':$scope.data_start, 'data_fim':$scope.data_end, 'funci':$scope.searchFunc})
  //$http.post('assets/php/remessa_rj.php', dados)
  .then(function(resu){
    $scope.thead = false;
    //console.log(resu);
    $scope.remessa = resu.data;
  });
};

$scope.SelectAll = function(){ // select all checkboxes to save in txt file
    //console.log($scope.remessa);
    angular.forEach($scope.remessa, function(item){
      item.selected = event.target.checked;
    });
  };

$scope.salvar = function(){ // employees selected in the box above
    $scope.funciSelected = [];

    // verifica se o vetor $scope.funciSelected foi selecionado alguma vez
    var n = $("input:checked").length - 1; 
    
    if (n === 0) { //console.log("The array is empty!") 
      $scope.funciSelected = 'No employees selected';
      console.log('empty');
    }

    else {   

      angular.forEach($scope.remessa, function(rem){
        if (rem.selected) {
          //console.log(rem.id_funci);
          //$scope.funciSelected.push({'id':rem.id_funci, 'name':rem.name});
          //console.log(rem);
                    
          /* send to file to save in txt */
          // here is the big problem when redirects to save/test.php
          $http.post('salvar/teste.php', rem)
          .then(function(resu){
            console.log(resu);
            window.location.href = 'save/test.php';
          });

          /* end - send to file to save in txt */
        }

      }); // end angular.forEach

  } // end else

  };

我需要重定向到这个 php 页面并打印 angularjs 中通过 post 传递的值,但它打印了 null。

$json = file_get_contents('php://input');
$obj = json_decode($json, TRUE);

foreach ($obj as $key => $value) {
   //$value has the value of each item
   echo($value);
}

//var_Dump($obj);

当朋友路过时,我尝试了几种方法,我在论坛上搜索但没有成功。

php angular post null 返回

评论


答: 暂无答案