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?

wowzuzz
  • 1,398
  • 11
  • 31
  • 51

1 Answers1

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

DarkAjax
  • 15,955
  • 11
  • 53
  • 65