2
I am passing an object from angular to php, but php insisted and "say" that the data that is coming is not an Object, what should I do? How can I get this data in php?
Just follow my codes
angular:
angular.module('app.controllers', [])
.controller('logradouroCtrl', function ($scope, $http, $window) {
var pegaMsgsLogra = function () {
idCep = $window.localStorage.getItem('idCep');
idUsuario = $window.localStorage.getItem('idUsuario');
var dados = {
idUsuario: $window.localStorage.getItem('idUsuario'),
idCep: $window.localStorage.getItem('idCep')
}
console.log(dados);
$http.get("http://localhost:8888/sistemas/sistemas_web/ionic/vcApp/www/php/pegaMsgsLogra.php", dados).success(function (data){
console.log(data);
});
}
pegaMsgsLogra();
php:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,X-Prototype-Version,X-Requested-With');
include_once("conPDO.php");
$pdo = conectar();
$data = file_get_contents("php://input");
$data = json_decode($data);
print_r($data);
$idUsuario = $data->idUsuario;
$idCep = $data->idCep;
echo 'id usuario '.$idUsuario.' id cep '.$idCep;
?>
I put the console.log(data) and print_r(data) to see what is going to php Follow picture:
Mistakes are here:
$data->idUsuario
and$data->idCep
.– felipsmartins
How? It’s wrong to do this @felipsmartins?
– GustavoSevero