Site icon Hip-Hop Website Design and Development

Jquery php request is returning a weird result

I am having a bit of a weird glitch happening to me and I am not sure how I have produced it or whether it is the norm.

I am developing my own plugin and when a football/soccer team is typed into a box it will check if its in the database already or not.

Here are my lines of code

add_action( 'admin_footer', 'fws_teamcheck_javascript' );
function fws_teamcheck_javascript() { ?>
<script type="text/javascript">
    jQuery(document).on('focusout', '.name', function () {
        var name = this.value;
        //alert(name);
        jQuery.ajax({
            type: 'POST',
            url: ajaxurl,
            data: {"action": "fws_check_name", "name": name},
            success: function (data) {
                alert(data);
                if(data=='true') {
                    $(".name").css("border", "solid 1px red");
                }
                if(data=='false') {
                    $(".name").css("border", "solid 1px green");
                }
            }
        });
    });
</script>
<?
}

function fws_check_name(){
    global $wpdb;
    $dbtable = $wpdb->prefix . 'fws_team_data';
    $name = $_POST['name'];
    $data = $wpdb->get_results($wpdb->prepare("SELECT * FROM $dbtable WHERE name = $name"));
    if($data) { echo 'true'; }else{ echo 'false'; }
    
}
add_action( 'wp_ajax_fws_check_name', 'fws_check_name' );
add_action( 'wp_ajax_nopriv_fws_check_name', 'fws_check_name' );

When i move away from the input it will bring up the alert as either true0 or false0 is there a reason why it is adding the 0 at the end?

Thanks for your input.