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

135
Visualizações
I can not to get the POST value from ajax

I would like to get the value from ajax with post in php, but this is not working, here is my code:

<script type="text/javascript">
    function deletarPerson(id_person) {
        let pag = "<?php echo plugin_dir_url(__DIR__) . 'admin/'; ?>";
        jQuery.ajax({
            url: pag + "/config.php",
            method: "post",
            data: {
                id_person: id_person
            },
            dataType: "html",
            success: function(result) {
                <?php
                    $aux = $_POST['id_person'];
                ?>
                alert('<?php echo $aux ?>')
            },
        })
    }
</script>

Someone can help me?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your Javascript ajax code:

function deletarPerson(id_person) {
    jQuery.ajax({
        url: "/echo.php", // <-- sending to echo.php on the server
                          // ...use whatever PHP file, on the server, 
                          // you need to get the necessary information
        method: "post",
        data: {
            id_person: id_person
        },
        dataType: "text",
        success: function(result) {
            alert(result) // <-- now use Javascript and the result variable,
                          // which is text sent back from the server,
                          // and do what you need to with it on the client
        },
    })
}

...and your PHP file:

<!-- echo.php -->
<?php

$aux = $_POST['id_person'];
echo $aux; // <-- whatever is echo'ed or print'ed in this file 
           // gets sent back to the server as text 
           // and is loaded in the Javascript result variable

// OR you can actually get some useful information from the server 
// and send that back instead

?>

Read more about the distinct executions contexts between PHP on the server and Javascript/HTML/CSS... on the client.

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