I have a PHP function server-side that looks like this:
function isHandleAvailable($displayname) {
$res = user::getRow(
"SELECT `id` FROM `users` WHERE `displayname` = :displayname",
array(':displayname' => $displayname)
);
if ($res) {
$res = 'Got a row!';
} else {
$res = 'No row :(';
}
echo $res;
}
and it's used to determine if a display name is already being used on the site. This function is called by the following JavaScript:
function checkHandleAvailability(displayName, callback) {
$.ajax({
type: 'POST',
url: '/users/isHandleAvailable',
data: { displayname: displayName }
})
.done(function(data, textStatus, jqXHR) {
isHandleAvailable = data;
})
.fail(function() {
isHandleAvailable = false;
})
.always(function() { callback(); });
}
however, the data
and jqXHR.responseText
are both an empty string. I know the PHP code is working because I put it into a basic test.php
page and got the expected strings echo
ed to the screen.
Why isn't the result getting back to the .done
function?