I'm new to AngularJS but I've already done a lot of things.
I did a $http.post, that worked like a charm.
Heres the Angular code
$scope.login = function(user, pass) {
$scope.bIsVisible = false;
var dados = {"user": user, "pass": pass};
console.log(dados);
$http.post('http://base.corretoconcursos.com.br/cadernos/index.php/manageUsers/login', dados)
.success(function(data, status, headers, config) {
if (data == false)
{
$scope.isLogged = false;
$scope.bIsVisible = true;
} else {
$scope.isLogged = true;
$scope.userData = data;
console.log(data);
}
})
.error(function(data, status, headers, config) {
alert('failed');
$scope.bIsVisible = true;
});
And the manageUsers/login function
function login()
{
$postdata = file_get_contents("php://input");
$data = json_decode($postdata);
$username = $data->user;
$password = md5($data->pass);
$datafrombase = $this->UsersModel->getUser(array(
'user' => $username,
'pass' => $password
));
if ($datafrombase != null) {
$user = array(
'user' => $datafrombase['user'],
'type' => $datafrombase['type'],
'logged_in' => true
);
$this->session->set_userdata($user);
}
if ($datafrombase != null)
print_r(json_encode($datafrombase));
else
return false;
}
Alright. It's working. I retrieve some data from database and OK. The real problem is when I do a $http.get and simply by doing a request on database or not, it doesn't send back the data that I want, when I do the console.log(data), it shows me an entirely HTML page, in fact, the one that is displaying. I'm getting a 200 status OK, but, a HTML page is coming. Don't know why.
Heres the Angular code
$scope.setLoggedOn = function(on) {
if (on) {
$http.get('http://base.corretoconcursos.com.br/cadernos/index.php/manageUsers/retrieveLogin')
.success(function(data, status) {
console.log(data);
})
.error(function(data, status, headers, config) {
alert('failed');
});
}
else
$scope.isLogged = false;
};
And heres the PHP code function I'm retrieving.
function retrieveLogin()
{
$user = null;
$user = array(
'user' => $this->session->userdata('user'),
'type' => $this->session->userdata('type'),
'logged_in' => true
);
print_r(json_encode($user));
}
I'm stuck. I've even tried doing just a 'return true'; inside the php function, return 'string'; but nothing will work. What so wrong am I doing?