Pass array as parameter for web api in php with angularjs

0

In my local environment I use PHP7 and developed API Restful for an application that uses AngujarJS. I needed to do a get request for Api and pass an array as a parameter and I did it that way

$http.get("/Api/MinhaUrl.php", {
    params: {
        "Nomes[]": ["João", "Maria"]
    }
})
.then(function(response){ //dispara ao realizar requisição com sucesso
    console.log(response.data);
}, function(response){ //dispara ao falhar
    console.log(response.statusText);         
});

In my file MyUrl.php I printed the parameters on the screen as follows:

<?php
   print_r($_GET);
?> 

When executed it was printed on the browser console exactly what I expected, like this:

Array
(
    [Nomes] => Array
        (
            [0] => João
            [1] => Maria
        )

)

So far no problem. However, when I upload this application to the server, which only supports PHP version 5.6 (I do not know if this is related to the problem but I think so), the parameter with the array is received by PHP in another way, and what is printed on the browser console is as follows:

Array
(
    [Nomes%5B%5D] => Maria
)

It "understands" the signs of [] by their HTML codes% 5B and% 5D, takes only the last element of the array and interprets it as a common variable.

What should I do to read the parameters on the server the same way I read in the local environment?

    
asked by anonymous 17.02.2017 / 14:37

1 answer

0
$http(
  method: 'GET',
  url: '/items',
  params: {
    id: JSON.stringify(ids) // ids is [1, 2, 3, 4]
  }
)

It is there, as the variable ids is an array. I hope I have helped!

    
17.02.2017 / 18:32