waitingtocompile waitingtocompile - 1 year ago 98
PHP Question

PHP AJAX success value empty

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


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


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

return $info;

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

Answer Source

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

return $info;

with this:

echo $info;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download