How to use $ http.post and $ http.get in the same function?

3

A few weeks ago I started using AngularJs for an application of the typical administration style.

My question is this:

I use it with PHP, using the method $http.post sent the parameters to a file 'file.php', who takes the variables and runs a query on MySQL.

I also use $http.get to receive arrays from another .php file.

Now the question, how can I use $http.post and $http.get in the same function?

Suppose that in php I need to do something like this:

<?php
 include('conn.php');
 $data = json_decode(file_get_contents('php://input'));

 $variable = $conn->real_escape_string($data->variable);

 $query = 'INSERT INTO datos VALUES ("'.$variable.'")';
 $conn->query($query);

 print $query;

?>

I need to pass parameters to php, that php execute what I need, and that I return something "x" by print , therefore in Angular, I need to send the parameters, and then receive them, all from the same file, Any ideas?

    
asked by Gabriel Gomez 23.09.2016 в 00:48
source

2 answers

2

To detect the method in which the request was made, you can use:

$_SERVER['REQUEST_METHOD']

For example:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     // Logica para solicitudes POST
} else if ($_SERVER['REQUEST_METHOD'] === 'GET') {
     // Logica para solicitudes GET
}

More info here .

    
answered by 23.10.2016 в 17:16
0

You can use $_REQUEST to read both GET and POST data. Then you combine them with an is and you have solved the problem. link

    
answered by 23.09.2016 в 06:46