Send and receive array via jQuery

Asked

Viewed 321 times

1

I am unable to send and read an array via jQuery, could help me?
My sending is like this:

var tipoAtividade = $('#arrayTipoAtividade:checked').serialize();

The variable type Activity is receiving this data:

tipo_atividade%5B%5D=AGUA&tipo_atividade%5B%5D=ALMOCO

How do I read this variable, like when I use a foreach to read a php array?

  • Please be more specific. What is #arrayTipoAtividade? Try making an example with the HTML of that part as well. What type of request is being sent (GET or POST)?

  • It seems to me that the variable has some kind of accentuation. The correct would not be to generate something like tipo_atividade=AGUA&tipo_atividade=ALMOCO?

2 answers

0

PHP will receive this data and store it in an array, see example:

<?php
$tipo_atividade = $_GET['tipo_atividade'];
foreach($tipo_atividade as $tipo){
    echo($tipo . '<br>');
}
?>

0

These strange characters are [] for the html array. Try sending this data by post instead of get, but anyway get more information so we can help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.