PHP is not returning request data

Asked

Viewed 83 times

0

I have 2 drop-downs. When a value is selected in the first one, the second one should list data referring to that value. However, my php, I think, is not getting the data sent. Can anyone help me?

Informações no console

Tabela sub_cat_entrada

Follow my codes:

<body ng-app="app" ng-controller="statecontroller">
<label>Categorias</label>
<select ng-model="contas.categoria">
    <option value="">Selecione</option>
    <option ng-repeat="x in categorias" value="{{ x.id_categoria }}">{{ x.categoria }}</option>
</select>

<label>Subcategorias</label>
<select ng-model="contas.subcategoria">
    <option value="">Selecione</option>
    <option ng-repeat="x in subcategorias" value="{{ x.id_subcategoria }}">{{ x.subcategoria }}</option>
</select>
</body>

<script src='js/angular.min.js'></script>
<script>
var app = angular.module("app",[]);
app.controller("statecontroller", ['$scope', '$http', function ($scope, $http) {

$http.get("php/carregaCategorias.php").success(function(response) {
    //console.log(response)
    $scope.categorias=response;
});

$scope.$watch('contas.categoria', function(newValue){
if(angular.isDefined(newValue)){
    $http.get('php/carregaSubCategorias.php?idCategoria=' + newValue).then(function(response){
        console.log(response)
    $scope.subcategorias = response.data;
  });
}
})


}]);
</script>

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);

include_once("conexao.php");
$pdo = conectar();

header('Content-Type: application/json');

$postdata = json_decode(file_get_contents('php://input'));
$request = json_decode($postdata);
$idCategoria = $request->idCategoria;

$buscaCategoria=$pdo->prepare("SELECT * FROM sub_cat_entrada WHERE    id_categoria=:id_categoria ");
$buscarUsuario->bindValue(":id_categoria", $idCategoria);
$buscarUsuario->execute();

$return = array();

while ($linha=$buscarUsuario->fetch(PDO::FETCH_ASSOC)) {
    array_push($return, $linha);
}

echo json_encode($return);

?>
  • try to place a URL inside $htto.get(), even if it is the localhost.

  • @Rafaelacioly, this part is working, the problem is in php.

  • Does anyone have any idea, please?

No answers

Browser other questions tagged

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