【问题标题】:Array empty after posting data from angular controler从角度控制器发布数据后数组为空
【发布时间】:2017-06-01 10:20:19
【问题描述】:

我正在为我的应用程序使用 codeigniter 和 angular。当我将数据从角度控制器发布到 CI 控制器时,数组似乎是空的(print_r 的结果是“array()”)。有人能告诉我为什么吗?

角部分:

$scope.posaljiKontroleru = function () {
    $scope.prosek = {kalorije: 0.0, proteini: 0.0, uh: 0.0, masti: 0.0};
    $http({
        method: 'POST',
        url: 'http://localhost/psi/Pravljenjejela/dodajBazi',
        data: $scope.prosek
    }).then(function (res) {
        $window.location.href = "http://localhost/psi/Pravljenjejela/dodajBazi";
        }, function (err) {
            console.log(err);
        });
    });
}

CI部分

public function dodajBazi() {
    $info = $this->input->post();
    print_r($info);
}

【问题讨论】:

  • 使用浏览器中的开发者工具检查请求并查看数据是否真的被发送。然后确认 $this->input->post() 确实是获取该帖子数据的合适方法。

标签: javascript php angularjs arrays codeigniter


【解决方案1】:

您需要使用默认的内容类型标题

试试这个:

$http({
   method: 'POST',
   url: 'http://localhost/psi/Pravljenjejela/dodajBazi',
   data: $scope.prosek,
   headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function (res) {
   $window.location.href = "http://localhost/psi/Pravljenjejela/dodajBazi";
}, function (err) {
 console.log(err);
});

【讨论】:

    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 2021-10-08
    • 2014-10-16
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多