How to access, in PHP, values passed as a parameter using jQuery.post ()

0

How can I access the values of the string cores and the filmes array on a PHP page individually?

var filmes = ["Mad Max", "Assassin's Creed"];

var cores = "cor_um=Azul&cor_dois=Preto";

$.post("autosave.php", {'_cores': cores, '_filmes': filmes});
    
asked by anonymous 26.01.2017 / 18:29

1 answer

1

Using the $ _POST tag

$filmes = $_POST['_filmes'];
parse_str($_POST['cores'], $cores);

To get each value of the submitted arrays, just use foreach

foreach($filmes as $filme) {
    print_r($filme)
}

I recommend you change the format of your color variable to an array instead of query string

    
26.01.2017 / 18:44