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.

2
  • 3
    Possible duplicate of Ajax passing data to php script Commented Nov 19, 2015 at 12:15
  • you are missing a slash in the ending <script> tag Commented Nov 19, 2015 at 12:25

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.