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


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 $ 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 $ and $http.get in the same function?

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

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

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

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

 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

2 answers


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


For example:

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

More info here .

answered by 23.10.2016 в 17:16

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