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

272
Visualizações
how to echo the ajax data with the help of php?

I trying to print the data which was entered by the user, and transfer that through ajax and trying to print or echo it with the help of php code, but I could not do that. enter code here this is my code:

`<html>
<head>
<title>
test ajax
</title>
<script src = "jquery.js"></script> 
</head>
<body>
<h2>test button</h2><br>
<form>
<input type = "text"id = "a"><br>
<input type = "button" id = "b"  value = "display">
</form>
<script>
$(document).ready(function(){
$('#b').click(function() {
let a = $('#a').val();
alert(a);
$.ajax({
type: "POST",
url: "same_file.php",
data: {c: a},
success: function() {
}

});    

});
});
</script>
</body>
</html>
<?php
extract($_POST);
if(isset($_POST["c"])) {
echo $_POST["c"];
}
?>

`

I think that, I have the problem with the php code. please give me any solution.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try it like this

This is your Html

<html>
  <head>
    <title>
      test ajax
    </title>
  <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  </head>
  <body>
    <h2>test button</h2><br>
    <form>
      <input type = "text" id = "a" > <br>
      <input type = "button" id = "b"  value = "display" >
    </form>
  </body>
</html>

<script>
    $(document).ready(function(){
        $('#b').click(function() {
            let a = $('#a').val();
            //alert(a);
            $.ajax({
                type: "POST",
                url: "same_file.php",
                data: {c: a},
                success: function(response) {
                    alert(response);
                }

            });    

        });
    });
</script>

This is your same_file.php

<?php
//extract($_POST); code works even without this

if(isset($_POST["c"])) {
  echo $_POST['c'];
}
?>

Not sure if your jquery library call is ok so I called the one on the web instead. Also your success:function() was not doing anything which is why you didn't receive anything.

Also always format your code with some indention so that it can be easier to read and comprehend by others.

over 4 years ago · Santiago Trujillo 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