0
Good evening, everyone,
I’m trying to pass parameters from my controller to php that searches the database and I’m not getting it. I’m passing the data as json object.
controller:
var buscaCategorias = function(){
var idempresa = $window.localStorage.getItem('idemp');
var opcao = 'pegarCategoria';
var buscaCat = {
"opcao": opcao,
"idempresa": idempresa
};
console.log(buscaCat);
$http.post('http://localhost:8888/sistemas/webApps/fluxo_de_caixa/fluxojoin_2.0/php/buscaCatSubcat.php', buscaCat).success(function(data){
console.log(data);
});
};
buscaCategorias();
In this console.log(buscaCat), what it shows is Object {option: "pegarCategoria", idempresa: "3"}
PHP:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
include_once("con.php");
$pdo = conectar();
$data = file_get_contents("php://input");
$data = json_decode($data);
$opcao = $data->opcao;
switch ($opcao) {
case 'pegarCategoria':
$idempresa = $data->idempresa;
$buscaCategoria=$pdo->prepare("SELECT categoria, idcategoria FROM categoria WHERE empresa_idempresa=:idempresa ");
$buscaCategoria->bindValue("idempresa", $idempresa);
$buscaCategoria->execute();
$return = array();
while ($linhaCat=$buscaCategoria->fetch(PDO::FETCH_ASSOC)) {
$linhaCat['categoria'] = $linhaCat['categoria'];
$linhaCat['idcategoria'] = $linhaCat['idcategoria'];
$return = $linhaCat;
}
echo json_encode($return);
break;
Trying to pass an object on
$http.get
, that works?– Jéf Bueno
I don’t know kkkkk
– GustavoSevero
I can only do this using $routeParams?
– GustavoSevero
Don’t need quotes I know inside the object keys searchCat.
var buscaCat = {
 opcao : opcao, 
 idempresa: idempresa
 };
– Diego Souza
I took this example from w3schools kkkkk’s website
– GustavoSevero
I’m already accessing the bank. But now only 1 dice, of 2, is coming.
– GustavoSevero