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

111
Vistas
PHP doesn't receive ajax post data

I have been struggling with it for a week...I want to use Ajax in datatables to pass some parameters to my PHP file for server side searching. But it seems my PHP file got nothing. But the datatable works just fine and the table can return from sever side processing and display on the html page correctly. However, var_dump( $_POST['species']) returns null.

  $(document).ready(function() {
    console.log(species);
    $("#table").DataTable({
      "destroy": true,
      "serverSide": true,
      "processing": true,
      "paging": false,
      "searching": false,

      columns: [{
          data: "dRid"
        },
        {
          data: "chromosome"
        },
        {
          data: "position"
        }
      ],
      ajax: {
        type: "POST",
        data: {
          "species": species
        },
        url: "./php/search_test.php"
      }

    });
  });
<div class="container text-center" id="tablecontainer" name="tablecontainer">
  <table id="table" class="display nowrap row-border strip p-2" cellspacing="0" width="100%">

    <thead class="thead-dark">
      <tr>
        <th>
          <center>directRMDB ID</center>
        </th>
        <th>
          <center>Chromosome</center>
        </th>
        <th>
          <center>Position</center>
        </th>

      </tr>
    </thead>
  </table>
</div>

'''php

ini_set ('memory_limit',  '2048M');
$sql_details = array(
'host' => 'localhost',
'user' => 'root',
'pass' => '',
'db'   => 'xxxxx'
);

// DB table to use
$table = 'homo_sapiens';

//if I try this here: $species=$_POST["species"]; echo $species;It //returns: Warning: Undefined array key "species".

// Table's primary key
$primaryKey = 'dRid';

// column
$columns = array(
array( 'db' => 'dRid', 'dt' => 'dRid' ),
array( 'db' => 'chr', 'dt' => 'chromosome' ),
array( 'db' => 'pos',  'dt' => 'position' ),


);

// Include SQL query processing class
require( 'ssp.class.php' );

echo json_encode(
SSP::complex( $_POST, $sql_details, $table, $primaryKey,$columns)
);

Could someone help me with it? Thanks.
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this. Replace $_POST to $array

$array = json_decode(file_get_contents('php://input'), true); print_r($array);

about 4 years ago · Juan Pablo Isaza 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