访问从angularJS传递数据对象到php

时间:2015-08-22 07:19:14

标签: php angularjs

我是angularJS的新手,我对它印象深刻。这就是为什么我要对它进行自学,这可能是一个重复的问题,很抱歉。

我的问题是如何访问我从angular传递给php的对象....

这是我的代码:

$scope.login = function(){
    console.log($scope.users);
    $http({
        method:'POST',
        url:'db/connection.php',
        data: $scope.users,
        headers:{'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'}
    }).success(function(res){
        console.log(res);
    }).error(function(error){
        console.log(error);
    });
};

PHP

  <?php
       //access the pass objects here.
       //i've tried using `$_POST['username']` but give me undefined error.
       //and i have also tried echoing on the php file to see if it returns a value and it's working.

CONSOLE LOG

Object {username: "sampleuser", password: "samplepass"}
controller.js:15 <br />
<b>Notice</b>:  Undefined index: username in    <b>D:\xamp\htdocs\angularjs\db\connection.php</b> on line <b>3</b><br />

先谢谢你们。

0 个答案:

没有答案