Ajax search shows all results when user empties input?

The regular WordPress search returns all posts if no search term is entered. You’ll notice this when using the default search form. If you don’t want your AJAX search to behave this way then you need to check if a search term has been entered before doing anything else:

if ( ! empty( $_POST['keyword'] ) && $query->have_posts() ) {

Or better yet, just don’t send the AJAX request if there’s no search term:

var keyword = jQuery('#keyword').val();

if ( keyword ) {
    jQuery.ajax({
        url: '<?php echo admin_url('admin-ajax.php'); ?>',
        type: 'post',
        data: {
          action: 'data_fetch',
          keyword: keyword
        },
        success: function(data) {
            jQuery('#datafetch').html( data );
        }
    });
} else {
    jQuery('#datafetch').html( '' );
}