How to pick up php data passed by parameter with Angular

Asked

Viewed 284 times

2

I need to take 1 data passed from the angular controller to my php file, as I do?

app.controller("EditarPerfilCtrl", function ($scope, $http, $window) {

var idempresa = $window.localStorage.getItem('idemp');
var empresa = $window.localStorage.getItem('empresa');
var usuario = $window.localStorage.getItem('usuario');
var idusuario = $window.localStorage.getItem('idusuario');

$scope.empresa = empresa;
$scope.usuario = usuario;

var params = {
    idusuario: idusuario
}

var buscaUsuario = function(){
        $http.get("http://localhost:8888/sistemas/webApps/fluxo_de_caixa/fluxojoin_2.0/php/buscaUsuario.php", params).then(function(data){
        console.log(data);
    });
}

buscaUsuario();

});

php:

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

include_once("con.php");

$pdo = conectar();

$params = $_GET['params'];
print_r($params);
?>
  • which error?

  • 1

    "<br /> <b>Notice</b>: Undefined index: params in <b>/Applications/MAMP/htdocs/systems/webApps/fluxo_de_box/fluxojoin_2.0/php/searchUsuario.php</b> on line <b>9</b><br />

  • Already tried to give print_r($_GET) just to see what returns?

  • I got it from the guy downstairs, but it’s a different problem now. This appears on the console: ""Uncaught Syntaxerror: Missing ) after argument list" and points to this line: $http.get("localhost:8888/systems/webApps/fluxo_de_box/Fl uxojoin_2.0/... ;, params: params). then(Function(date){"

1 answer

1

First, you have to pass the parameters, right?!

Where has params you have to say what you want to pass. Even if you have created a variable with the data, params is still an attribute of $http get..

var params = {
    "id-usuario": idusuario
};

var config = {
    params: params
};

var buscaUsuario = function(){
    $http.get("http://localhost:8888/sistemas/webApps/fluxo_de_caixa/fluxojoin_2.0/php/buscaUsuario.php", config).then(function(data){
        console.log(data);
    });
};

So in PHP, you can do:

<?php

//Recebe o ID do $http.get
$id_usuario = $_GET['id-usuario'];

var_dump($id_usuario);
  • I did as you passed, above, and the following message appears on the console: "Uncaught Syntaxerror: Missing ) after argument list" and points to this line: $http.get("http://localhost:8888/systems/webApps/fluxo_de_box/fluxojoin_2.0/php/buscaUsuario.php", params: params). then(Function(date){

Browser other questions tagged

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