0

I have a project made in angularjs. i need click the botton prueba and send one parameter to the phpfile to validate if its a number xxxx, return some information, if its other number, return other information. I have to receive the number in the file php and code a if structure but I couldn't receive the parameter en the php file.

Here is my code

HTML

<!DOCTYPE html>
<html ng-app="AppUts">
  <head>    
    <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> 
    <meta charset='utf-8'>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </head>

  <body ng-controller="EstudiantesController as estCtrl">

    <input ng-model="info" class="form-control" id="identificacion" type="text" placeholder="Nro Identificación" />
    <button  ng-click="estCtrl.traer()" class="btn btn-success" id="boton">seguir</button>      
    <button  ng-click="estCtrl.traer2()" class="btn btn-success" id="boton">prueba</button>     


    <div class="list-group">

      <div id="destino_datos_estudiante">
      </div>      

      <div class="list-group-item" id="jsones" ng-show="estCtrl.datos[0].isError">
        nombre de estudiante
        <h3>{{estCtrl.datos[0].nombreEstudiante}}</h3>
        programa
        <h3>{{estCtrl.datos[0].nombrePrograma}}</h3>

      </div>      
    </div>  
  </body>
</html>

JS

(function() {
  var app = angular.module('AppUts', []);

      app.controller('EstudiantesController', ['$http', function($http){

      var estudiante = this;
      estudiante.datos = [];    

    estudiante.traer = function(){
    $http.get("datos_estudiante.php").success(function(data){
            estudiante.datos = data;
        }); 
    }



    estudiante.traer2 = function(){

    estudiante.jsonData = {num: 1, num: "manzana"}

        $envio = $http({
           url: "datos_estudiante.php",
           method: "POST",
           data: {val: 3}
        }).success(function(){
            console.log($envio);
        });



    }


    }]);
})();

PHP

<?php 

    $data = file_get_contents("php://input");
    $objData = json_decode($data);


    $datosEstudiante[] = ["nombreEstudiante" => "Andres Mogollon",
                          "nombrePrograma" => "Tecnologia Desarrollo Sistemas Informaticos",
                          "progId" => 1,
                          "estudianteId" => 1,
                          "msg" => "vacio",
                          "isError" => true                      
                          ];
    echo json_encode($datosEstudiante); 

?>

Thank you

an dres
  • 13
  • 6
  • possible duplicate of [How to pass variables and data from PHP to JavaScript?](http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript) – tcooc Sep 23 '15 at 21:37
  • Hello, thanks for answering... but is not the same, its de opposite, I need send data from angular to php – an dres Sep 23 '15 at 22:00
  • Its exactly the same. The client sends a request to the server, which responds. – tcooc Sep 23 '15 at 22:05
  • Sorry, but i can't understand, i've tried do it a lot and anything – an dres Sep 23 '15 at 22:14
  • have you check the content of the `$objData` ? i believe that contains the data that you are looking for. – MuntingInsekto Sep 24 '15 at 06:53
  • Yes, but i dont know how to use it in php, because if a write "$objData->val" it doesn't work – an dres Sep 24 '15 at 15:36

0 Answers0