Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda