2014-01-18 39 views
-1
var app = angular.module("report", []); 

function index($scope, $http){ 

    $scope.auth = function(){ 
     $http({ 
      url: '/index.php/users/auth', 
      method: "POST", 
      data: {login: $scope.login, password: $scope.password} 
     }).success(function(data){ 
       alert(data); 
      }); 
    } 

} 

這是我的AngularJS應用程序。 $ http不會將POST數據發送到php腳本。

<?php 
class Users extends CI_Controller { 
    public function auth(){ 
     extract($_POST); 
     echo $login; 
    } 
} 

- 這是我的PHP腳本。 Codeignitor回報不確定的變量'登錄'

+1

爲了確保Codeigniter不會「清除」你的$ _POST(出於安全目的??),爲什麼不把你的print_r($ this-> input-> post());.更好的是,使用Chrome Developer窗口來檢查請求(在網絡選項卡下)以查看post參數是否已正確發送。 – Yman

+0

有點偏離主題,但使用控制檯檢查該成功功能的數據輸出。它可以幫助您更深入地瞭解(如@Yman建議的)發送到服務器的內容。 – gonzofish

回答

0

請使用json_decode(的file_get_contents('PHP ://輸入'));

例如:

public function auth(){ 
    $postData = json_decode(file_get_contents('php://input')); 
}