Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
Can I post an JS array to php via ajax, if button is pressed?

I need to pass valuesArray to php if button is clicked, when anotherButton is clicked, i want to print this array in PHP.

home.js:

button.onclick = function (){

    valuesArray = ['a', 'b', 'c']

$.post('index.php', {data: valuesArray});
}

index.php:

<?php
    If(isset($_POST['anotherButton'])){
        $getData = $_POST['data'];
        print_r($getData);
    } 
?>

If button gets clicked I get

undefined index: data

which should mean that data wasn't passed to PHP.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

$.post('index.php', {"data": valuesArray},function(return,result){});

Notice the double quote around "data".
Also may need to json encode valuesArray?

about 4 years ago · Santiago Trujillo Denunciar

0

$.post('index.php', valuesArray, function(result) {
    // ....
});

Have a look at documentation: https://api.jquery.com/jquery.post/

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda