How to pass a php array as a paramera of $ .ajax data?

1

How to pass a php array as paramera of $ .ajax data? Ex:

<?php $nomes = array('maria','joao','jose'); ?>

  $.ajax({
    url: 'pagina.php',
    dataType: 'json',
    method: 'POST',
    data: {'nomes' : <?php echo json_encode($nomes); ?>},
    sucesss: function(data){
      console.log(data);
           }
     });

And on the page get this array.

    
asked by anonymous 08.04.2016 / 18:17

1 answer

-2

nomes = [];
nomes[0] = 'maria';
nomes[1] = 'joao';
nomes[2] = 'josé';


$.ajax({
   type: "POST",
   data: {nomes :nomes},
   url: "pagina.php",
   success: function(msg){
     console.log(data);
   }
});
    
10.04.2017 / 15:11