Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

codeigniter angular js how to receive json data

codeigniter angular js how to receive json data  using -'php,json,angularjs,codeigniter,post'

This is the situation:

I have a simple app made in Angular JS that comunicate with the server through an API made in codeigniter.

There is a login system in the app. When the user enter email and password, this data are sent to the server, if the email exist and the password match, it return true.

I have made many attempts but not figure out how can i do this properly.

This is the code:

The form:

<form role="form" method="post" novalidate ng-submit="submitForm()">
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" name="email" ng-model="" placeholder="Enter email">
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" name="password" ng-model="user.password" placeholder="Password">

  <button type="submit" class="btn btn-default">Submit</button>

This is the Angular js controller:

 $scope.authorized = false;

 $scope.user = {};

 $scope.submitForm = function()
    console.log("posting data....");

        method : 'POST',
        url : '',
        headers: {'Content-Type': 'application/json'},
        data : JSON.stringify({email:$, password:$scope.user.password})
    }).success(function(data) {

        $scope.authorized = data;

        if ($scope.authorized) { $location.path("memberArea"); };        



In the codeigniter method have tried many things.
Right now there is just this:

function login()
    print json_encode($_POST);

But i don't know if can receive the data into the $_POST because it seems to be empty.

So the question is:

How can i receive data in the codeigniter method?
Is better to send as JSON and then json_decode?
I have also tried json_decode($_POST, true);
But was null.
But if the data are not in $_POST where are?
I am little confused..

Thank you for help!


Thanks guys for reply.
That was one thing that have tried. But somehow is not working.
Now for example the method is like this:

function login()
    $email = $this->input->post('email');
    print json_encode($email);

But what is returned is a boolean false.

asked Sep 15, 2015 by ClaShuster
0 votes

Related Hot Questions

Government Jobs Opening