I think I'm doing this wrong for what I want returned with PHP. What I'm trying to do is check if the username is paid or not via ajax.
The PHP, which works by itself if I do this:
$username = $_POST['username'];
function checkPlayer($player) {
$mcURL = 'http://www.minecraft.net/haspaid.jsp?user=';
$auth = file_get_contents($mcURL . $player);
if (trim($auth) == "true") {
echo $player. ' is ';
} else {
echo $player. ' is ';
}
return $auth;
}
echo checkPlayer($username);
Does what I want if I change $username value to something static, like $username = "Notch";. But not if I use $_POST['username'], and use the following JS:
$(document).on('keyup', 'input', function(){
var inputVal = $('input').val();
$.post('auth.php', inputVal, function(data){
console.log(input.Val + ' is ' data);
});
});
Which should print out in console if I typed in 'Notch', true, if something else like 'fslfjslkfjls' should be false.
HTML:
<form>
<input type="text" name="username" value="" class="authcheck">
</form>
What do I have wrong?
UPDATE: After galchen's answer, it (kinda) works now (doesn't give an error)
var inputVal = $('input').val();
$.post('auth.php', { 'username' : inputVal }, function(data){
console.log(inputVal + ' is ' + data);
});
But now everything that inputs returns true, even if it's not true. How can I fix this?