I scanned a lot of answers here but didn't find a good answer. I'm new to PHP and JavaScript and want to create a variable (for comparison purposes) from a jQuery return value. I'm creating a registration system where I use this to check username availability:
$(document).ready(function() {
$("#username").keyup(function (e) {
//removes spaces from username
$(this).val($(this).val().replace(/\s/g, ''));
var username = $(this).val();
if(username.length < 2){$("#user-result").html('');return;}
if(username.length >= 2){
$("#user-result").html('<i class="fa fa-refresh fa-spin"></i>');
$.post('core/check_username.php', {'username':username}, function(data) {
$("#user-result").html(data);
});
}
});
});
I can display the return value in a span but for form validation purpose, I need to compare this return value with a set of criteria. How can I declare a variable from this return value?