1

I am trying to send a variable from one PHP file to another PHP file and echo it:

<script>
 $.ajax({
        type: "POST",
        url: 'AjaxCallTest.php',
        data: ({Imgname:"13"}),
        success: function() {
            alert('form was submitted');
        }
    });
<script>

And then in the receiving PHP file (AjaxCallTest.php):

<?php
    $temp = $_POST['Imgname'];
    echo $temp;
?>

but AjaxCallTest file doesn't echo anything? I need to get this variable and echo it. Note that I've included jQuery library in my code but I didn't include it in AjaxCallTest.php.

henser
  • 3,307
  • 2
  • 36
  • 47
M.Ahmed
  • 67
  • 1
  • 9

3 Answers3

1

replace this line data: ({Imgname:"13"}), with data: {"Imgname":"13"}

Santosh Patel
  • 549
  • 2
  • 13
0

I tried this and it worked! Notice the closing <script> tag

I also added the return result to check the echo in 'AjaxCallTest.php'

<script>
 $.ajax({
        type: "POST",
        url: 'AjaxCallTest.php',
        data: ({Imgname:"13"}),
        success: function(result) {
            alert(result + ' form was submitted');
        }
    });
</script>
Lucky Chingi
  • 2,248
  • 1
  • 10
  • 15
0

Your code worked fine for me. One error I could find is that you didnt closed the script tag correctly. close the script tag.

<script>
 $.ajax({
        type: "POST",
        url: 'AjaxCallTest.php',
        data: ({Imgname:"13"}),
        success: function() {
            alert('form was submitted');
        }
    });
<script>
akhilp2255
  • 330
  • 3
  • 13