How to get data Object in php?

Asked

Viewed 236 times

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:

inserir a descrição da imagem aqui

  • Mistakes are here: $data->idUsuario and $data->idCep.

  • How? It’s wrong to do this @felipsmartins?

1 answer

4


Changes the $http.get for $http.post

$http.get does not allow you to pass a set of data per parameter.

$http get.

$http.post allows you to pass a set of data per parameter

$http post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.