-1

I've been having trouble with AJAX requests giving blank responses. Minimal version of the problem:

test.html:

<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
    function request() {
        $.ajax({
            url: 'test.php',
            type: 'post',
            data: {'info': 'thing'},
            success: function(response)
            {
                alert(response);
            }
        });
    }
</script>
<button onclick="request();">TEST</button>
</body>
</html>

test.php

$info = 'nope';
if(isset($_POST['info'])) $info = $_POST['info'];

return $info;

When I press the button the alert box is simply blank.

1 Answers1

1

test.php doesn't output anything. Replace this:

return $info;

with this:

echo $info;
David
  • 208,112
  • 36
  • 198
  • 279