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

263
Vistas
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 Respuestas
Responde la pregunta

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 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