Update $wpdb query with AJAX

You need the function accessible to the AJAX hook when it’s fired, so move the get_states_by_ajax_callback function to your functions.php