Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!