1

I am trying to pass a value of a button using some ajax to a separate file.

Here is my code.

            $("input#downloadSingle").click(function() {
                var myData = $("input#downloadSingle").val();
                $.ajax({
                    type: 'post',
                    url:'singleDownload.php',
                    data: myData,
                    success: function(results) {
                        alert('works');
                    }
                });
            });

However, when I test out the next page by doing a var_dump on $_POST. I don't get any data back. Thoughts?

3
  • What browser? What host (localhost?)? I guess Google Chrome ;) Commented Nov 20, 2012 at 15:47
  • 1
    Check the network tab of your debugger if it actually sends the data and if the server acknowledges it. Also check the console for errors. Commented Nov 20, 2012 at 15:47
  • There you go stackoverflow.com/questions/5796087/… Commented Nov 20, 2012 at 15:48

1 Answer 1

6

You're not specifying the name of the $_POST variable you're gonna get on the singleDownload.php file (unless that's part of the button's value), so you should try something like:

        $("input#downloadSingle").click(function() {
            var myData = "whatever=" + $("input#downloadSingle").val();
            $.ajax({
                type: 'post',
                url:'singleDownload.php',
                data: myData,
                success: function(results) {
                    alert('works');
                }
            });
        });

And make sure $_POST in your php file is the same whatever variable

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

1 Comment

This worked for me. So, are we setting a post key here with whatever?

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.