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

}

This is my AngularJS application. $http doesn't send POST data to the php script.

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

- This my php script. Codeignitor return that undefined variable 'login'

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    To make sure if the Codeigniter doesn't "cleanup" your $_POST (for security purposes??), why don't your print_r($this->input->post());. Better still, use Chrome Developer window to check the Request (under Network tab) to see if the post param has been sent correctly. – Yman Jan 18 '14 at 12:47
  • Kind of off-topic, but use the console to check the data output on that success function. It'll help give you more insight (as @Yman suggested) into what is being sent to the server. – gonzofish Jan 18 '14 at 14:09

3 Answers3

0

You need to use file_get_contents function, provided by php.


You can find an explanation here:

AngularJs $http.post() does not send data

You can find a code example here:

http://www.cleverweb.nl/javascript/a-simple-search-with-angularjs-and-php/

Community
  • 1
  • 1
0

Please use json_decode(file_get_contents('php://input'));

for example:

public function auth(){
    $postData = json_decode(file_get_contents('php://input'));
}
Emil Reña Enriquez
  • 2,929
  • 1
  • 29
  • 32
0

Solving this problem without changing code in server and use $_POST the regular way. Explained here: http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/

vikramaditya234
  • 1,278
  • 2
  • 18
  • 37