2017-06-01 41 views
0

我对我的应用使用了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); 
} 
+0

使用开发工具您的浏览器来检查请求t并查看数据是否真的被发送。之后确认$ this-> input-> post()确实是获取该发布数据的合适方法。 – Xatenev

回答

0

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

试试这个:

$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); 
});