-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
  • it should be: data: {info: 'thing'}, Commented Aug 14, 2016 at 20:20

1 Answer 1

1

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

return $info;

with this:

echo $info;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.